【问题标题】:Django migrations not applied to the connected databaseDjango 迁移未应用于连接的数据库
【发布时间】:2019-10-10 22:59:15
【问题描述】:

所以我正在调整现有的 django (v1.11.5) 项目并迁移我的修改:

$ python2 manage.py makemigrations
Migrations for 'genetics_ark':
  genetics_ark/migrations/0002_analysis_analysisvariant_annotation_cnv_decon_deconcnv_decongene_decongenecnv_deconsample_gene_genep.py
    - Create model Analysis
    - Create model AnalysisVariant
    - Create model Annotation
    - Create model Gene
    - Create model GenePanel
    - Create model Meta
    - Create model Model
    - Create model ModelRegion
    - Create model Panel
    - Create model Reference
    - Create model Region
    - Create model SamplePanel
    - Create model Transcript
    - Create model TranscriptRegion
    - Create model CNV
    - Create model Decon
    - Create model DeconCNV
    - Create model Decongene
    - Create model DecongeneCNV
    - Create model DeconSample

$ python2 manage.py migrate
System check identified some issues:

WARNINGS:
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default'
        HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
?: (mysql.W002) MySQL Strict Mode is not set for database connection 'genetics_ark_db'
        HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-sql-mode
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, genetics_ark, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... 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 genetics_ark.0001_initial... OK
  Applying genetics_ark.0002_analysis_analysisvariant_annotation_cnv_decon_deconcnv_decongene_decongenecnv_deconsample_gene_genep... OK
  Applying sessions.0001_initial... OK

但是,我添加的模型没有添加到数据库中,而 django 部分是:

  • auth_group
  • auth_group_permissions
  • auth_permission
  • auth_user
  • auth_user_groups
  • auth_user_user_permissions
  • django_admin_log
  • django_content_type
  • django_migrations
  • django_session

我已经使用项目的先前版本修改了数据库,但我找不到任何可以解释为什么它不起作用的差异。此外,当我“运行服务器”时,它不起作用,终端中也没有显示错误消息。 有什么建议吗?

【问题讨论】:

  • 如果不是太麻烦,您可以简单地删除 migrations 文件夹并在 Postgres 中删除并重新创建数据库,然后 python2 manage.py makemigrations [app]python2 manage.py migrate。这样您就可以再次获得干净的设置。

标签: python mysql django


【解决方案1】:

您可以在设置中静音个别检查。例如,如果您确定 django_mysql.W002 不需要您注意,请将以下内容添加到 settings.py:

SILENCED_SYSTEM_CHECKS = [
    'django_mysql.W002',
]

你可以看到这个document

【讨论】:

    【解决方案2】:

    试试

    python2 manage.py makemigrations <app_name>
    

    Django 在初始阶段没有检测到迁移的变化。所以你必须第一次指定应用程序名称。之后你可以简单地做

    python2 manage.py makemigrations
    

    【讨论】:

    • 不幸的是,它没有用。此外,自从我从我们的 gitlab 克隆项目以来,已经有一个初始阶段。
    • 您的项目中是否有迁移文件夹?如果没有尝试创建一个并在其中创建一个 init.py 并尝试再次迁移。
    • 我对模型所做的修改有迁移文件
    猜你喜欢
    • 2021-05-01
    • 2017-08-19
    • 2014-08-11
    • 1970-01-01
    • 2016-10-08
    • 2018-03-04
    • 2014-10-15
    • 2012-08-15
    • 2019-12-01
    相关资源
    最近更新 更多