Django:迁移期间发生ValueError(如何修复???)

时间:2019-01-29 16:15:09

标签: python django

我有2节课。学生和家长。父类通过 models.ForeignKey(Student,on_delete = models.CASCADE)链接到学生类。 在运行makemigrations时,django询问我是否要输入,因为没有默认值。所以我输入“ defult”。原来它需要一个字符串,现在每当我运行 migrate 时,它就会给我ValueValue,我不知道如何解决或怎么做。我尝试删除迁移文件夹并删除两个模型,但仍然没有。

C:\Users\Egor\Desktop\mysite>python manage.py makemigrations
    Migrations for 'main':
  main\migrations\0028_auto_20190129_2010.py
    - Alter field student_joined on student

C:\Users\Egor\Desktop\mysite>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, main, sessions
Running migrations:
  Applying main.0007_auto_20190129_1732...Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-            
packages\django\core\management\__init__.py", line 381, in 
execute_from_command_line
utility.execute()
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
fake_initial=fake_initial,
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\migrations\operations\fields.py", line 84, in database_forwards
field,
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\schema.py", line 309, in add_field
self._remake_table(model, create_field=field)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\schema.py", line 181, in _remake_table
self.effective_default(create_field)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\base\schema.py", line 239, in effective_default
return field.get_db_prep_save(default, self.connection)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\fields\related.py", line 937, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\fields\__init__.py", line 790, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\fields\__init__.py", line 956, in get_db_prep_value
value = self.get_prep_value(value)
  File "C:\Users\Egor\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\fields\__init__.py", line 965, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'Defult'

型号代码:

class Student(models.Model):
    student_name = models.CharField(max_length=200)
    student_gender = models.CharField(max_length=1)
    student_parent_email = models.EmailField()
    student_joined = models.DateTimeField('date joined', default=datetime.now())


    def __str__(self):
        return self.student_name


class Parent(models.Model):
    mother = models.CharField(max_length=200)
    father = models.CharField(max_length=200)
    stu = models.ForeignKey(Student, on_delete=models.CASCADE)

我不知道现在该怎么办。请提供有关如何消除此值错误的帮助。

谢谢

0 个答案:

没有答案