有!
我一直在努力克服这个错误,我已经搜索了stackoverflow并发现了非常类似的帖子,但没有一个建议的解决方案适合我。
这是我在控制台中遇到的错误:
(pyblog) SATCHELs-MacBook-Pro:src satchel$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, contenttypes, posts, auth, sessions
Running migrations:
Rendering model states... DONE
Applying posts.0002_post_updated...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/migrations/migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
field,
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/backends/sqlite3/schema.py", line 229, in add_field
self._remake_table(model, create_fields=[field])
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/backends/sqlite3/schema.py", line 111, in _remake_table
self.effective_default(field)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 210, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 728, in get_db_prep_save
prepared=False)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1461, in get_db_prep_value
value = self.get_prep_value(value)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1440, in get_prep_value
value = super(DateTimeField, self).get_prep_value(value)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1296, in get_prep_value
return self.to_python(value)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1399, in to_python
parsed = parse_datetime(value)
File "/Users/satchel/Desktop/py/webground/pyblog/lib/python2.7/site-packages/django/utils/dateparse.py", line 93, in parse_datetime
match = datetime_re.match(value)
TypeError: expected string or buffer
这是我的model.py:
from __future__ import unicode_literals
from django.db import models
from django.core.urlresolvers import reverse
#from django.utils import
# Create your models here.
class Post(models.Model):
title = models.CharField(max_length=120)
image = models.FileField(null=True, blank=True)
content = models.TextField()
timestamp = models.DateTimeField(auto_now = False, auto_now_add = True)
def __unicode__(self):
return self.title
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse("posts:detail", kwargs = {"id": self.id})
#return "/posts/%s/"(self.id)
从类似的问题我猜它与DateTimeField有关,并解析我给出的任何参数的问题。
非常感谢任何帮助,谢谢!
答案 0 :(得分:0)
我实际上最终重命名了我的迁移文件夹,创建了一个新文件夹,然后运行以下命令:
python manage.py makemigrations posts
python manage.py migrate posts
感谢@FeFiFoFu,您的提示引导我走向正确的道路