Django更改数据库中的迁移表名称

时间:2020-04-17 06:21:43

标签: django migration

我该如何为django_migrations表名称添加服装?

即使我编辑

venv.lib.site-packages.django.db.migrations.recorder> MigrationRecorder> meta = db_table =“ ABC_django_migrations”

makemigrations无法检测到更改。

我正在使用Django版本:3.0.5

2 个答案:

答案 0 :(得分:2)

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 :(得分:0)

我如何解决此问题:

  1. 安装应用

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

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

    DB_PREFIX = "foo_"
    
相关问题