本文介绍了Django 1.8 Migration不创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

yekabathula-macbookair2:roster yekabathula$ python manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: staticfiles, messages
  Apply all migrations: admin, contenttypes, api, auth, sessions
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying api.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying sessions.0001_initial... OK
yekabathula-macbookair2:roster yekabathula$ python manage.py syncdb
/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command will be removed in Django 1.9
  warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)

Operations to perform:
  Synchronize unmigrated apps: staticfiles, messages
  Apply all migrations: admin, contenttypes, api, auth, sessions
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  No migrations to apply.

执行python manage.py迁移后,不是从我的models.py数据库中创建表能够从django_session等创建其他表。这里还有其他需要我遵循的东西吗?

After doing python manage.py migrate, tables are not created in database from my models.py it is able to create other tables from django_session etc. Is there anything else that I need to follow here ?

推荐答案

我面临着类似的问题Django 1.10中的问题,上述解决方案都不适合我。

I was facing a similar problem in Django 1.10 and none of the above solutions worked for me.

运行此命令最终有效:

python manage.py migrate --fake myappname zero

这将重置所有迁移(到第零状态),然后是:

This followed by :

python manage.py migrate myappname

为我创建了表。

如果您不想回滚到初始(零)状态,而是说迁移号0005(有效的最后一次迁移),则可以执行以下操作:

If you do not want to roll back to the initial(zero) state but say to the migration number 0005(the last migration that worked), you can instead do this:

python manage.py migrate --fake myappname 0005

然后继续进行实际迁移:

And then proceed with the actual migrate:

python manage.py migrate myappname

更多信息

这篇关于Django 1.8 Migration不创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:05