2016-05-22 14 views
0

があります!djangoの日付解析/タイプエラー

私はこのバグを少しでも乗り越えようとしています。私は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です:私はそれがDateTimeField型とは何かを持って推測している同様の質問から

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) 

私がそれを与えた何らかの議論を解析する問題があります。

ご協力いただきありがとうございます!

+0

はすでにあなたを行います日時ではないタイムスタンプフィールドにデータがありますか? – FeFiFoFu

+0

@FeFiFoFu Nope、すべてのデータを削除して、もう一度試してみました。運がない。 – Satchel

+0

新しいプロジェクトと新しいデータベースでmodel.pyを実行しましたが、うまくいきました。 – FeFiFoFu

答えて

0

私は実際に新しいものを作り、私の移行フォルダの名前を変更することになったし、次のコマンドを実行している:

python manage.py makemigrations posts 
python manage.py migrate posts 

おかげ@FeFiFoFu、あなたの先端を正しい道に私を導く