Reputation: 2069
How can I custom the django_migrations table name?
Even I edit the
venv.lib.site-packages.django.db.migrations.recorder > MigrationRecorder > meta = db_table = "ABC_django_migrations"
the makemigrations cannot detect the changes.
I am using Django version: 3.0.5
Upvotes: 3
Views: 1479
Reputation: 2069
How I solve this problem:
Install the app
pip install django-db-prefix
Include the apps in Settings.py
INSTALLED_APPS = ['django_db_prefix',]
Adding the prefix in Settings.py
DB_PREFIX = "foo_"
Upvotes: 1
Reputation: 15728
Django migrations don't look for changes in its own migration model
MigrationExecutor
just ensures that following table exists in database
def migrate(self, targets, plan=None, state=None, fake=False, fake_initial=False):
self.recorder.ensure_schema()
....
where ensure_schema()
just creates the table
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)
you can manually make migration to edit this model ( AlterModelTable
or custom sql) but I would not advise changing anything regarding migrations
Upvotes: 3