【问题标题】:Running "migrate" won't produce migrations folder运行“迁移”不会生成迁移文件夹
【发布时间】:2020-01-07 07:27:40
【问题描述】:

正如标题所说,运行 python manage.py migrate 会运行迁移,但在 app 目录中没有生成迁移目录,因此不存在来自 models.py 的表。

  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... 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 auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK

这对我来说是一个全新的错误。我该怎么办?

【问题讨论】:

  • 这不是错误。它只是说明它应用了哪些迁移。您首先需要makemigration 生成迁移文件。

标签: django


【解决方案1】:

python manage.py migrate 只运行现有的迁移,它不会进行新的迁移。你要找的可能是python manage.py makemigrations

【讨论】:

  • python manage.py makemigrations 什么也没给我:No changes detected
  • 如果您获得No changes detected,则使用python manage.py makemigrations yourapp 为您的应用创建初始迁移。见stackoverflow.com/questions/36153748/…
【解决方案2】:

您应该检查您的migrations 目录中是否包含一个空的__init__.py 文件。然后在 INSTALLED_APP(在 settings.py 中)添加您的应用名称(或应用地址),然后使用 python manage.py makemigrations 制作迁移文件。

现在你可以使用迁移命令了!

【讨论】:

  • 按照建议,我创建了 migrations 目录,其中包含初始化文件,它现在可以工作了。祝福你哥们!
【解决方案3】:

你可以试试:

python manage.py migrate 'yourappname'

或者:

python manage.py makemigrations 'yourappname'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    • 2018-03-07
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    相关资源
    最近更新 更多