Opened 3 years ago

Last modified 2 years ago

#24484 assigned Cleanup/optimization

Add a helpful message when running tests with models without migrations

Reported by: Chris Adams Owned by: Karl Hobley
Component: Testing framework Version: master
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 (9)

comment:1 Changed 3 years ago by Tim Graham

Component: DocumentationTesting framework
Summary: Poor user experience with migrations and running testsAdd a helpful message when running tests with models without migrations
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization
Version: 1.7master

It seems better to exit with a helpful message rather than have to lookup some documentation.

comment:2 Changed 3 years ago by Karl Hobley

Owner: changed from nobody to Karl Hobley
Status: newassigned

comment:3 Changed 3 years ago by Markus Holtermann

Has patch: set

comment:4 Changed 3 years ago by Markus Holtermann

Patch needs improvement: set

comment:5 Changed 3 years ago by Markus Holtermann

Please note #24412 which requests a similar change.

comment:6 Changed 2 years ago by Peter Schmidt

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.

Last edited 2 years ago by Peter Schmidt (previous) (diff)

comment:7 Changed 2 years ago by Tim Graham

Patch needs improvement: unset

comment:8 Changed 2 years ago by Tim Graham

Keywords: 1.9 added
Patch needs improvement: set

comment:9 Changed 2 years ago by Tim Graham

Keywords: 1.9 removed
Note: See TracTickets for help on using tickets.
Back to Top