#25388 closed New feature (fixed)
Allow disabling of all migrations during tests
Reported by: | Markus Holtermann | Owned by: | |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | berker.peksag@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As an extension to #24919 a setting DATABASE['TEST']['MIGRATE'] = False
should disable all migrations on that particular database. This can be done by hooking into django.db.migrations.loader.MigrationLoader.migrations_module()
and returning None
.
Change History (23)
comment:1 by , 9 years ago
Has patch: | set |
---|---|
Needs documentation: | set |
Needs tests: | set |
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 9 years ago
Cc: | added |
---|---|
Patch needs improvement: | set |
comment:3 by , 9 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
Updated PR: https://github.com/django/django/pull/6323
comment:6 by , 8 years ago
Has patch: | unset |
---|---|
Resolution: | fixed |
Severity: | Normal → Release blocker |
Status: | closed → new |
Version: | master → 1.10 |
As described in #26838, this feature doesn't seem to work as migrations are disabled in more than just tests when setting DATABASES['default']['TEST'] = {'MIGRATE': False}
. If this requires more than a trivial fix, let's remove the feature from 1.10.
comment:9 by , 8 years ago
Resolution: | fixed |
---|---|
Severity: | Release blocker → Normal |
Status: | closed → new |
Version: | 1.10 → master |
comment:10 by , 8 years ago
Here's a WIP concept: https://github.com/django/django/compare/master...berkerpeksag:25388-migrate-false-v2 Added an attribute to BaseDatabaseWrapper
to be used during the creation of the test database. It's probably not the best way to solve the problem, but it prevents the bug described in #26838.
comment:11 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Assigned to myself due to inactivity for 2 months.
Working on top of Berker's solution.
comment:12 by , 8 years ago
Has patch: | set |
---|
Patch submitted https://github.com/django/django/pull/7499
it wasn't possible to write tests because setting "_run_in_test_case" on the connection only works before creating the test DB.
I tried override setting and creating "ConnectionHandler" but failed because of the reason above.
comment:14 by , 8 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
Owner: | removed |
Patch needs improvement: | set |
Status: | assigned → new |
follow-up: 17 comment:15 by , 8 years ago
Another option (which I prefer over the current implementation, the more I think about it) would be to add a new option to the migrate
management command that would *only* run syncdb
(i.e., it would pass an argument into the MigrationLoader
telling it to do what you do now in the above PR). This seems less magical than the current implementation as it would facilitate passing the option down through the stack rather than setting it on a global variable (the db connection).
comment:16 by , 8 years ago
Another question: What about the currently documented method of suppressing migrations is insufficient? I.e., would simply improving that documentation be a suitable alternative to this ticket?
comment:17 by , 8 years ago
Replying to Tobias McNulty:
Another option (which I prefer over the current implementation, the more I think about it) would be to add a new option to the
migrate
management command that would *only* runsyncdb
I don't like that option. syncdb in it's current form will go away in some way or another in the future. migrate
doesn't run syncdb automatically anymore unless explicitly said otherwise.
comment:18 by , 8 years ago
Assigned to myself due to inactivity for 2 months.
Thank you for working on this, Eyad. By the way, the inactivity was mainly due to the lack of feedback. I'm not very experienced on this part of Django and I wasn't sure that my solution is a good one. So it would be great if you could get some feedback from the domain experts :)
comment:19 by , 8 years ago
My take on the motivation of this ticket is to ease the boilerplate of setting MIGRATIONS_MODULES['app'] = None
for all apps in a test settings file. I think it has some value if a nice solution is found.
comment:20 by , 5 years ago
This would be a very welcome addition to Django. In the mean time, we've been adding the following to all our projects test_settings
to speed up testing:
class NoMigrations: """Disable migrations for all apps""" def __getitem__(self, item): return None def __contains__(self, item): return True MIGRATION_MODULES = NoMigrations()
comment:21 by , 5 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
I took a new approach in PR https://github.com/django/django/pull/12062
https://github.com/django/django/pull/5601