我有2节课。学生和家长。父类通过型号.外键(学生,请删除)=模型.CASCADE) 在运行makemigrations时,django问我是否需要输入,因为没有默认值。所以我输入“defult”。原来它需要一个字符串,现在每当我运行migrate时,它都会给我一个ValueError,我不知道如何修复或做什么。我试过删除migrations文件夹并删除这两个模型,但仍然没有。你知道吗
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)
我不知道现在该怎么办。请帮助解决这个值错误。你知道吗
谢谢
目前没有回答
相关问题 更多 >
编程相关推荐