与docker的Django不运行自定义应用程序的迁移
我在我的项目的根目录中创build了一个名为bay
的自定义应用程序,结构如下所示 –
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
。
我相信这是一个文件权限问题,在我的migrations
文件夹中看到__init__.py
文件和__pycache__
文件夹上的locking符号。 最初忽略它,因为它与我现有应用程序的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
- Docker与多个Dockfiles和图像组成(Django + Angular)
- Jenkins继续以root身份运行slave操作
- 无法构builddocker-compose构build
- Django +docker到弹性豆茎
- 将Django连接到现有的Docker Postgres容器
- 如何使redis BROKER_URLdynamic部署到AWS实例
- uWSGI通过Docker的Supervisord服务应用程序
- 当docker运行时,会发生错误。 “ValueError:无法configuration处理程序”守望台“:您必须指定一个区域。”
- Python中的AWS Elastic Beanstalk container_commands 3.4 Docker容器