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 Tim Graham, 10 years ago

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 by Karl Hobley, 10 years ago

Owner: changed from nobody to Karl Hobley
Status: newassigned

comment:3 by Markus Holtermann, 10 years ago

Has patch: set

comment:4 by Markus Holtermann, 10 years ago

Patch needs improvement: set

comment:5 by Markus Holtermann, 10 years ago

Please note #24412 which requests a similar change.

comment:6 by Peter Schmidt, 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 1.8:
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.

Version 0, edited 9 years ago by Peter Schmidt (next)

comment:7 by Tim Graham, 9 years ago

Patch needs improvement: unset

comment:8 by Tim Graham, 9 years ago

Keywords: 1.9 added
Patch needs improvement: set

comment:9 by Tim Graham, 9 years ago

Keywords: 1.9 removed

comment:10 by Mariusz Felisiak, 4 years ago

Owner: Karl Hobley removed
Status: assignednew
Note: See TracTickets for help on using tickets.
Back to Top