Ali*_*ari 0 python sql django orm django-models
我正在Django写一个简单的游戏,所有的事情都是正确的,但突然......我遇到了以下错误:
我不知道这些代码有什么问题:
(test)alireza@alireza:~/test/test1$ python manage.py syncdb
Operations to perform:
Synchronize unmigrated apps: django_admin_bootstrapped, django_admin_bootstrapped_bootstrap3, crispy_forms
Apply all migrations: contenttypes, admin, auth, arosis, sessions
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying arosis.0008_auto_20150212_0826...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/alireza/test/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/alireza/test/lib/python3.4/site-
...
...
...
return self.to_python(value)
File "/home/alireza/test/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 1252, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
Run Code Online (Sandbox Code Playgroud)
class Move(models.Model):
"""docstring for Move"""
x = models.IntegerField()
y = models.IntegerField()
comment = models.CharField(max_length=30)
game = models.ForeignKey(Game)
by_first_player = models.BooleanField(default=True)
timestamp = models.DateTimeField(auto_now_add=True)
def __str__(self):
return "{}".format(self.comment)
class Meta:
get_latest_by = 'timestamp'
def player(self):
return self.game.first_player if self.by_first_player else self.game.second_player
Run Code Online (Sandbox Code Playgroud)
我给了
auto_now_add=True,
但首先,当我跑:
python manage.py makemigrations
Run Code Online (Sandbox Code Playgroud)
它要求我输入默认值 DateTimeField()
我该怎么办?
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('arosis', '0007_auto_20150211_1844'),
]
operations = [
migrations.AlterModelOptions(
name='move',
options={'get_latest_by': 'timestamp'},
),
migrations.AddField(
model_name='move',
name='by_first_player',
field=models.BooleanField(default=True),
preserve_default=True,
),
migrations.AddField(
model_name='move',
name='timestamp',
field=models.DateTimeField(default='', auto_now_add=True),
preserve_default=True,
),
]
Run Code Online (Sandbox Code Playgroud)
Ben*_*min 13
我有类似的事情.从文件夹/迁移中删除所有迁移,然后运行python manage.py makemigrations,然后运行python manage.py migrate.这对我有用.
| 归档时间: |
|
| 查看次数: |
8007 次 |
| 最近记录: |