2017-04-19 31 views
1

我创建一个名为我的项目的根目录bay一个自定义应用程序,结构看起来就像下面 -Django的与码头工人不运行自定义应用程序的迁移

project_root/ 
    - bay/ 
     - migrations/ 
      - __init__.py 
      - 0001_initial.py 
     - models/ 
      - __init__.py 
      - document.py 
      - ... (other model files) 

当我试图挽救一个新的模型实例从我的一个自定义应用程序的模型,我收到以下错误 -

postgres_1 | ERROR: relation "bay_brand" does not exist at character 13 
postgres_1 | STATEMENT: INSERT INTO "bay_brand" ("name") VALUES ('xyz') RETURNING "bay_brand"."id" 

因此,尚未运行给定模型的迁移。所以,我尝试使用迁移 -

sudo docker-compose -f dev.yml run django python manage.py migrate 

导致

Postgres is up - continuing... 
Operations to perform: 
    Apply all migrations: account, admin, auth, contenttypes, sessions, sites, socialaccount, users 
Running migrations: 
    Applying contenttypes.0001_initial... OK 
    Applying contenttypes.0002_remove_content_type_name... OK 
    Applying auth.0001_initial... 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 users.0001_initial... OK 
    Applying account.0001_initial... OK 
    Applying account.0002_email_max_length... OK 
    Applying admin.0001_initial... OK 
    Applying admin.0002_logentry_remove_auto_add... OK 
    Applying sessions.0001_initial... OK 
    Applying sites.0001_initial... OK 
    Applying sites.0002_alter_domain_unique... OK 
    Applying sites.0003_set_site_domain_and_name... OK 
    Applying socialaccount.0001_initial... OK 
    Applying socialaccount.0002_token_max_lengths... OK 
    Applying socialaccount.0003_extra_data_default_dict... OK 
    Applying users.0002_auto_20170419_1104... OK 

清楚上述不显示bay.0001_initial迁移它应该有运行。所以,我继续前进,看到

sudo docker-compose -f dev.yml run django python manage.py makemigrations bay 

输出导致

Postgres is up - continuing... 
Migrations for 'bay': 
    bay/migrations/0001_initial.py: 
    - Create model Brand 
    - Create model ... 
    - ... 

如果我尝试再次运行migrate命令,它说No migrations to apply

回答

0

我相信这是一个文件权限问题,看到migrations文件夹中__init__.py文件和__pycache__文件夹上的锁定符号。最初忽略它,因为它与我现有应用程序的migrations文件夹中的类似,但这些迁移确实运行良好。

删除的文件夹migrations在我的自定义应用程序,运行makemigrations命令,然后migrate成功 -

Postgres is up - continuing... 
Operations to perform: 
    Apply all migrations: account, admin, auth, bay, contenttypes, sessions, sites, socialaccount, users 
Running migrations: 
    Applying bay.0001_initial... OK 
相关问题