Permissions aren't created in time for latter migrations to use them in a single pass

464 views
Skip to first unread message

glenc

unread,
May 16, 2011, 5:11:00 PM5/16/11
to South Users
I'm not 100% sure I'm doing this right, but I think I've found an
issue where auth.Permission objects aren't being created soon enough
for migrations to use them when you initialize a DB from scratch.

The important details:

- I'm trying to initialize a Django DB from scratch using `./manage.py
syncdb --migrate --noinput`

- I have 11 migrations in my chain

- The 1st migration creates a new model called `myapp.CompanyAccount`

- The 9th migration tries to fetch the permission
`myapp.change_companyaccount` with:

`p = orm[ "auth.Permission" ].objects.get( codename =
"change_companyaccount" )`

At that point, an exception is raised:

`django.contrib.auth.models.DoesNotExist: Permission matching query
does not exist`

I had assumed that the built-in permissions that are created for every
object would have been created by the time the 1st migration finished,
but it doesn't appear that they are. If I re-run the migration after
the exception, it works the second time because apparently the
permission now exists and the 9th migration can execute without error.

Is there anything that can be done to "flush" everything sometime
before the 9th migration runs so that the whole thing can run in a
single pass without bailing out?

Thanks for any help / advice.

Andrew Godwin

unread,
May 16, 2011, 6:59:45 PM5/16/11
to south...@googlegroups.com

So, South runs all the post_syncdb signals (which do this sort of thing)
quite late in the process; to trigger them manually, you should call
db.send_pending_create_signals() from a migration, which should do the
trick.

Andrew

glenc

unread,
May 17, 2011, 9:09:35 AM5/17/11
to South Users
Awesome Andrew, thanks so much for this, it works perfectly now. Also
I posted on SO about this here, so others might find it:

http://stackoverflow.com/questions/6023508
Reply all
Reply to author
Forward
0 new messages