[Django] #25884: migrate --run-syncdb doesn't [seem to] work for app without migrations

40 views
Skip to first unread message

Django

unread,
Dec 7, 2015, 3:30:34 PM12/7/15
to django-...@googlegroups.com
#25884: migrate --run-syncdb doesn't [seem to] work for app without migrations
----------------------------+--------------------------------
Reporter: gertjanol | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Keywords: syncdb, migrations
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------
As [https://docs.djangoproject.com/en/1.9/ref/django-admin/#django-admin-
option---run-syncdb the docs state], "the --run-syncdb option allows
creating tables for apps without migrations.". However, this doesn't seem
to work. To demonstrate this, [https://github.com/gertjanol/django-test
I've created a very simple Django project] from the first steps of the
tutorial. When running 'python manage.py migrate --run-syncdb polls' I get
the error "CommandError: App 'polls' does not have migrations.", while I
expected an sqlite-database with the structure.

It makes no difference if I created a 'migrations' directory with just an
'__init__.py'.

Is this a bug, or is this intended behaviour and are the docs off (or do I
not understand them)?

I've managed to get the command working with some minor adjustments to
https://github.com/django/django/blob/1.9/django/core/management/commands/migrate.py,
but I'm too unfamiliar with the code to be sure I didn't break anything
else. I'll try to whip up a PR though.

--
Ticket URL: <https://code.djangoproject.com/ticket/25884>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 7, 2015, 6:19:26 PM12/7/15
to django-...@googlegroups.com
#25884: migrate --run-syncdb doesn't [seem to] work for app without migrations
------------------------------------+--------------------------------------
Reporter: gertjanol | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: invalid

Keywords: syncdb, migrations | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* needs_better_patch: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_docs: => 0


Comment:

You're missing the `'polls'` app in `INSTALLED_APPS`.

--
Ticket URL: <https://code.djangoproject.com/ticket/25884#comment:1>

Django

unread,
Dec 8, 2015, 3:30:36 PM12/8/15
to django-...@googlegroups.com
#25884: migrate --run-syncdb doesn't [seem to] work for app without migrations
------------------------------------+--------------------------------------

Reporter: gertjanol | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:

Keywords: syncdb, migrations | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Changes (by gertjanol):

* status: closed => new
* resolution: invalid =>


Comment:

Hi Tim,

Thanks, you're right of course, but that doesn't solve my problem. But I
think I've figured it out. If I run `./manage.py migrate --run-syncdb` it
indeed works as intended: the `polls` app is also synced to the database.
However, in our software stack we use a different database for each app,
with a router configured in `DATABASE_ROUTERS` that routes reads, writes,
relations and migrations.
In that case, we need to migrate each database to it's own database.
Before 1.9, we needed to specify the app that was being synced or
migrated. I just found out that with 1.9 that's no longer necessary. In my
example, these two commands gave the expected result: `./manage.py migrate
--run-syncdb` and `./manage.py migrate --run-syncdb --database polls`.

I've updated [https://github.com/gertjanol/django-test my example] at
github to demonstrate our router and settings.

I think this behaviour deserves a mention in the docs. Also, the error I
encountered is not very helpful. It should at least mention that `--run-
syncdb` it not possible when specifying an app. Why is that? When I change
[https://github.com/django/django/blob/e403f2217e67301526a0df5ea5be42e190e00e10/django/core/management/commands/migrate.py#L131
this line] to `if app_label not in executor.loader.migrated_apps and not
run_syncdb` (and move the assignment to `run_syncdb` higher) everything
works as I'd expect. I couldn't find any tests that documented this
behaviour :(.

--
Ticket URL: <https://code.djangoproject.com/ticket/25884#comment:2>

Django

unread,
Dec 8, 2015, 5:43:13 PM12/8/15
to django-...@googlegroups.com
#25884: migrate --run-syncdb doesn't work when specifying a database
------------------------------------+------------------------------------

Reporter: gertjanol | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:
Keywords: syncdb, migrations | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

This could very well be a bug as I didn't think or test the multiple
database support when adding `run_syncdb`. Feel free to submit a patch and
we can probably backport it to 1.9.

--
Ticket URL: <https://code.djangoproject.com/ticket/25884#comment:3>

Django

unread,
Jul 15, 2018, 11:15:21 PM7/15/18
to django-...@googlegroups.com
#25884: migrate --run-syncdb doesn't work when specifying a database
-------------------------------------+-------------------------------------
Reporter: Gertjan Oude Lohuis | Owner: Sarah
| Guermond
Type: Bug | Status: assigned
Component: Migrations | Version: 1.9

Severity: Normal | Resolution:
Keywords: syncdb, migrations | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Guermond):

* owner: nobody => Sarah Guermond
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25884#comment:4>

Django

unread,
Jul 15, 2018, 11:40:17 PM7/15/18
to django-...@googlegroups.com
#25884: migrate --run-syncdb doesn't work when specifying a database
-------------------------------------+-------------------------------------
Reporter: Gertjan Oude Lohuis | Owner: Sarah
| Guermond
Type: Bug | Status: assigned
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:
Keywords: syncdb, migrations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Guermond):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25884#comment:5>

Django

unread,
Jul 21, 2018, 5:54:24 PM7/21/18
to django-...@googlegroups.com
#25884: migrate --run-syncdb doesn't work when specifying a database
-------------------------------------+-------------------------------------
Reporter: Gertjan Oude Lohuis | Owner: Sarah
| Guermond
Type: Bug | Status: assigned
Component: Migrations | Version: 1.9

Severity: Normal | Resolution:
Keywords: syncdb, migrations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25884#comment:6>

Django

unread,
Nov 14, 2018, 6:49:34 PM11/14/18
to django-...@googlegroups.com
#25884: migrate --run-syncdb doesn't work when specifying a database
-------------------------------------+-------------------------------------
Reporter: Gertjan Oude Lohuis | Owner: Sarah
| Guermond
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: fixed

Keywords: syncdb, migrations | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"cd40306854bdeec7d961e3715fba0ba9f72f2f88" cd403068]:
{{{
#!CommitTicketReference repository=""
revision="cd40306854bdeec7d961e3715fba0ba9f72f2f88"
Fixed #25884 -- Fixed migrate --run-syncdb when specifying an app label.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25884#comment:7>

Reply all
Reply to author
Forward
0 new messages