Opened 10 years ago
Last modified 8 months ago
#24484 new Cleanup/optimization
Add a helpful message when running tests with models without migrations
Reported by: | Chris Adams | Owned by: | |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Prior to Django 1.7, you could create a new app and run tests immediately:
django-admin.py startapp new_app
… add a model & test …
django-admin.py test
Since Django 1.7, however, if you don't run makemigrations first the tests will fail in a manner which doesn't give any indication of what you can do to fix it. setup_databases() will eventually fail with a "OperationalError: no such table" for every model which doesn't have an initial migration.
I'm filing this under documentation because the easiest path to solve it would be updating the startapp and running tests docs to add a prominent notice somewhere that you must run makemigrations before you can run any tests but if there's a clean way to do it having setup_databases catch this and give a helpful message would probably save people some searching.
Change History (10)
comment:1 by , 10 years ago
Component: | Documentation → Testing framework |
---|---|
Summary: | Poor user experience with migrations and running tests → Add a helpful message when running tests with models without migrations |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
Version: | 1.7 → master |
comment:2 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 10 years ago
Patch needs improvement: | set |
---|
comment:6 by , 9 years ago
Ended up looking at this as part of my PyConAU yak shaving.
Squashed version for master:
https://github.com/django/django/pull/5100
Full branch, tests and reasoning in commits for code review:
https://github.com/pzrq/django/compare/ticket-24484-4
Squashed version rebased (some minor test merge conflicts) for testing against 1.8 (but probably should not apply to 1.8 without some performance fixes like #24743):
https://github.com/pzrq/django/compare/ticket-24484-4-squash-18
Let me know if anyone has any questions, e.g. it took my aging 2011 Macbook Air an extra ~17 seconds to run the has_unmigrated_models
before it was renamed to check_unmigrated_models
and some further refactoring applied. I also haven't thought about things like any possible interactions with things like --keepdb
, just run it against the full test suite under Python 3.4.
comment:7 by , 9 years ago
Patch needs improvement: | unset |
---|
comment:8 by , 9 years ago
Keywords: | 1.9 added |
---|---|
Patch needs improvement: | set |
comment:9 by , 9 years ago
Keywords: | 1.9 removed |
---|
comment:10 by , 4 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
It seems better to exit with a helpful message rather than have to lookup some documentation.