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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24484>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: Documentation => Testing framework
* needs_tests: => 0
* version: 1.7 => master
* needs_docs: => 0
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
It seems better to exit with a helpful message rather than have to lookup
some documentation.
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:1>
* status: new => assigned
* owner: nobody => kaedroho
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:2>
* has_patch: 0 => 1
Comment:
PR https://github.com/django/django/pull/4379
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:3>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:4>
Comment (by MarkusH):
Please note #24412 which requests a similar change.
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:5>
Comment (by pzrq):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:6>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:7>
* keywords: => 1.9
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:8>
* keywords: 1.9 =>
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:9>
* owner: Karl Hobley => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:10>
* owner: (none) => Aman Pandey
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/24484#comment:11>