Django更改DB中的迁移表名称



如何自定义django_migrations表名?

甚至我也编辑

venv.lib.site-packages.django.db.migrations.recorder>迁移记录器>meta=db_table=";ABC_ jango_;

makemigrations无法检测到更改。

我使用的是Django版本:3.0.5

Django迁移不会在自己的迁移模型中寻找变化

MigrationExecutor只是确保数据库中存在下表

def migrate(self, targets, plan=None, state=None, fake=False, fake_initial=False):
self.recorder.ensure_schema()
....

其中ensure_schema()仅创建表

def ensure_schema(self):
"""Ensure the table exists and has the correct schema."""
# If the table's there, that's fine - we've never changed its schema
# in the codebase.
if self.has_table():
return
# Make the table
try:
with self.connection.schema_editor() as editor:
editor.create_model(self.Migration)
except DatabaseError as exc:
raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)

您可以手动进行迁移以编辑此模型(AlterModelTable或自定义sql(,但我不建议更改任何有关迁移的内容

我如何解决这个问题:

  1. 安装应用

    pip install django-db-prefix
    
  2. 将应用程序包括在Settings.py 中

    INSTALLED_APPS = ['django_db_prefix',]
    
  3. 在Settings.py 中添加前缀

    DB_PREFIX = "foo_"
    

最新更新