#27054: makemigrations tries to create django_migrations in external database
---------------------------------+------------------------------------
Reporter: Jim Nicholls | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Comment (by MiddleFork):
Replying to [comment:16 Tim Graham]:
> You need to add an `allow_migrate()` method to your router.
OK, I can see that now.
Still, it's unfortunate that we need to identify
read-only databases in this manner, which if I understand correctly is
like this:
{{{
class MyRouter():
def allow_migrate(self, db):
if db in ['read_only0', 'read_only1',
'another_read_only_database_with_a_very_long_name']:
return False
}}}
Something like this might be fun:
{{{
DATABASES = {
'default' : {
'HOST': 'localhost',
'NAME': 'database0' },
'read_only': {
'NAME': 'database1',
'HOST': 'localhost',
'OPTIONS':
{'read_only': True,}
}
}
}}}
Then,
{{{
not DATABASES['default'].get('OPTIONS').get('read_only')
}}}
will return True,
and
{{{
not DATABASES['read_only'].get('OPTIONS').get('read_only')
}}}
will return False,
so back in makemigrations we can check:
{{{
# Non-default databases are only checked if database routers used.
aliases_to_check = connections if settings.DATABASE_ROUTERS else
[DEFAULT_DB_ALIAS]
for alias in sorted(aliases_to_check):
connection = connections[alias]
if (connection.settings_dict['ENGINE'] !=
'django.db.backends.dummy' and any(
# At least one model must be migrated to the database.
router.allow_migrate(connection.alias, app_label,
model_name=model._meta.object_name)
for app_label in consistency_check_labels
for model in
apps.get_app_config(app_label).get_models()
# The database must not be read-only
and not
connections.settings_dict.get('OPTIONS').get('read_only')
)):
loader.check_consistent_history(connection)
}}}
https://github.com/MiddleFork/django/commit/36641fca286a9687f6b1b4ff5605f2c0bc5565a2
#diff-8eb3b5673aa9386f8fcb2cd99a8ebce3
On further thought, the use of the term read_only is loaded and maybe
OPTIONS['migratable'] would be preferable
Anyway, it might be fun.
--
Ticket URL: <https://code.djangoproject.com/ticket/27054#comment:17>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/078.c906ed19db85baa1b99f1c5a4e0d437a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.