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
。