简体   繁体   English

Django manage.py syncdb:预期的字符串还是缓冲区?

[英]Django manage.py syncdb : expected string or buffer?

I am trying to synchronise my model with SQLite under django. 我正在尝试将我的模型与Django下的SQLite同步。 I went into the here-after error, and I can't find a way aruond. 我遇到了以后的错误,而我找不到一种可行的方法。 I hard-deleted the database file, and commented everything on my models.py. 我硬删除了数据库文件,并注释了我的models.py上的所有内容。 But still the manage.py doesn't wand to do any makemigrations, migration, or syncdd.... Any idea ? 但是manage.py仍然不希望进行任何makemigrations,migration或syncdd。...知道吗? Here is the error trace back : 这是错误回溯:

>> python2.7 manage.py syncdb
Operations to perform:
  Apply all migrations: admin, contenttypes, sessions, auth, database
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying database.0001_initial... OK
  Applying database.0002_userinfo... OK
  Applying database.0003_auto_20150201_0402...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 533, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 27, in handle_noargs
    call_command("migrate", **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 115, in call_command
    return klass.execute(*args, **defaults)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 102, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/migration.py", line 108, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/operations/fields.py", line 37, in database_forwards
    field,
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/schema.py", line 176, in add_field
    self._remake_table(model, create_fields=[field])
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/schema.py", line 74, in _remake_table
    self.effective_default(field)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/schema.py", line 187, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 627, in get_db_prep_save
    prepared=False)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1176, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1171, in get_prep_value
    return self.to_python(value)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1128, in to_python
    parsed = parse_date(value)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/dateparse.py", line 37, in parse_date
    match = date_re.match(value)
TypeError: expected string or buffer

So, the trick is that delete the database file is not enough : the process of migration create some files on the [migration] directory under the app. 因此,诀窍在于仅删除数据库文件是不够的:迁移过程会在应用程序下的[migration]目录上创建一些文件。 I moved all these files into another directory to help, but it didn't seem to be sufficient : I also had to precise the name of the app on the 3 operations : 我将所有这些文件移到另一个目录来提供帮助,但这似乎还不够:我还必须在3个操作中精确确定应用程序的名称:

1) python manage.py makemigrations APP-NAME
2) python manage.py migrate       APP-NAME
3) python manage.py syncdb

With everything deleted (database file + migration history) and the 3 operations applied, I have a brand new database to enjoy again ! 删除所有内容(数据库文件+迁移历史记录)并应用3个操作后,我有了一个全新的数据库,可以再次使用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM