我创建了一个新的模型名称加入三个字段,电子邮件,时间戳和更新的时间戳。但是,数据库同步开始给我添加默认值以创建表的错误。我添加了一些随机值,现在它开始给我完全随机的错误超出我的理解。请在这里帮忙。
这是我的模特:
class Join(models.Model):
email = models.EmailField(default="default@default.com")
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False, default = "")
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __unicode__(self):
return self.email
这是错误:
(learn_django) C:\Users\ajhavery\Desktop\learn_django\source>python manage.py ma
kemigrations
Migrations for 'joins':
0004_auto_20150320_2358.py:
- Alter field timestamp on join
- Alter field updated on join
(learn_django) C:\Users\ajhavery\Desktop\learn_django\source>python manage.py mi
grate
Operations to perform:
Apply all migrations: admin, contenttypes, joins, auth, sessions
Running migrations:
Applying joins.0002_auto_20150320_2346...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\core\man
agement\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\core\man
agement\__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\core\man
agement\base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\core\man
agement\base.py", line 338, in execute
output = self.handle(*args, **options)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\core\man
agement\commands\migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\migra
tions\executor.py", line 68, in migrate
self.apply_migration(migration, fake=fake)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\migra
tions\executor.py", line 102, in apply_migration
migration.apply(project_state, schema_editor)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\migra
tions\migration.py", line 108, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, ne
w_state)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\migra
tions\operations\fields.py", line 37, in database_forwards
field,
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\backe
nds\sqlite3\schema.py", line 179, in add_field
self._remake_table(model, create_fields=[field])
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\backe
nds\sqlite3\schema.py", line 75, in _remake_table
self.effective_default(field)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\backe
nds\schema.py", line 188, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\model
s\fields\__init__.py", line 627, in get_db_prep_save
prepared=False)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\model
s\fields\__init__.py", line 1290, in get_db_prep_value
value = self.get_prep_value(value)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\model
s\fields\__init__.py", line 1269, in get_prep_value
value = super(DateTimeField, self).get_prep_value(value)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\model
s\fields\__init__.py", line 1171, in get_prep_value
return self.to_python(value)
File "C:\Users\ajhavery\Desktop\learn_django\lib\site-packages\django\db\model
s\fields\__init__.py", line 1252, in to_python
params={'value': value},
django.core.exceptions.ValidationError: [u"'00:00:00' value has an invalid forma
t. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
请帮助。
答案 0 :(得分:1)
当Django要求&#34;添加默认值以创建表&#34;时,您需要创建与该特定列的TYPE共振的值。
你的错误在这里很明显: django.core.exceptions.ValidationError:[u&#34;&#39; 00:00&00; value的格式无效。它必须是YYYY-MM-DD HH:MM [:ss [.uuuuuu]] [TZ]格式。&#34;]
&#34;随机&#34;您输入的值必须为YYYY-MM-DD HH:MM [:ss [.uuuuuu]] [TZ]格式。
从模型中删除DateTimeFields,重新启动并重新开始。这一次,当您要求输入默认值时,请将其随机设置为日期时间&#39; (即2006-10-25 14:30:59)。
来源:https://docs.djangoproject.com/en/1.7/ref/forms/fields/#datetimefield
最佳, AJ