Opened 9 years ago

Closed 6 years ago

#25884 closed Bug (fixed)

migrate --run-syncdb doesn't work when specifying a database

Reported by: Gertjan Oude Lohuis Owned by: Sarah Guermond
Component: Migrations Version: 1.9
Severity: Normal Keywords: syncdb, migrations
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


As the docs state, "the --run-syncdb option allows creating tables for apps without migrations.". However, this doesn't seem to work. To demonstrate this, I've created a very simple Django project from the first steps of the tutorial. When running 'python 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 ''.

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, 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.

Change History (7)

comment:1 by Tim Graham, 9 years ago

Resolution: invalid
Status: newclosed

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

comment:2 by Gertjan Oude Lohuis, 9 years ago

Resolution: invalid
Status: closednew

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 ./ 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: ./ migrate --run-syncdb and ./ migrate --run-syncdb --database polls.

I've updated 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 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 :(.

comment:3 by Tim Graham, 9 years ago

Summary: migrate --run-syncdb doesn't [seem to] work for app without migrationsmigrate --run-syncdb doesn't work when specifying a database
Triage Stage: UnreviewedAccepted

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.

comment:4 by Sarah Guermond, 6 years ago

Owner: changed from nobody to Sarah Guermond
Status: newassigned

comment:5 by Sarah Guermond, 6 years ago

Has patch: set

comment:6 by Tim Graham, 6 years ago

Patch needs improvement: set

comment:7 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In cd403068:

Fixed #25884 -- Fixed migrate --run-syncdb when specifying an app label.

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