Django Unleashed, custom user model

157 views
Skip to first unread message

Malik Rumi

unread,
Jul 5, 2016, 9:49:01 PM7/5/16
to Django users
Hello, Andrew

All of our Tag, Startup, NewsLink, and Post will be right back in the database thanks to our data migrations. Example 22.40

Why? a) you dumped the whole database, and b) you only did makemigrations for the User app.

we opt to remove the CreateModel operation for Profile and move it into its own migration file. Example 22.39

I followed your example, but got this error

CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0002_profile, 0001_user in account). To fix them run 'python manage.py makemigrations –merge'

What happened here? The only obvious difference between your examples and mine is the Python version, and I don't see how that's relevant here. It seems to be purely a Django migrations thing.

thx

Malik Rumi

unread,
Jul 7, 2016, 12:39:27 PM7/7/16
to Django users
Waited as long as I thought I could to hear from you. So here's my result:

(cannon)malikarumi@Tetuoan2:~/Projects/cannon/jamf$ python manage.py makemigrations --merge

Traceback (most recent call last):

raise ValueError("Could not find common ancestor of %s" % migration_names)

ValueError: Could not find common ancestor of set([u'0002_profile', u'0001_user'])


(...so I re-merged them back into a single document...)

(cannon)malikarumi@Tetuoan2:~/Projects/cannon/jamf$ python manage.py makemigrations account
No changes detected in app 'account'
(cannon)malikarumi@Tetuoan2:~/Projects/cannon/jamf$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, account, contenttypes, auth, sessions
Running migrations:
  Rendering model states... DONE
  Applying account.0001_initial... OK
The following content types are stale and need to be deleted:

    auth | user

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: no
(cannon)malikarumi@Tetuoan2:~/Projects/cannon/jamf$

I thought you should be aware of these differing results.

Andrew Pinkham

unread,
Oct 23, 2016, 11:36:35 AM10/23/16
to django...@googlegroups.com
Hi Malik,

I'm sorry to hear that you are still having trouble with Chapter 22. I've attempted to answer your questions below based on the limited information you have provided. You might find a comparison with the book code helpful for future problems (https://github.com/jambonrose/DjangoUnleashed-1.8).

On Jul 5, 2016, at 9:49 PM, Malik Rumi <malik....@gmail.com> wrote:
> Why? a) you dumped the whole database, and b) you only did makemigrations for the User app.

Please see the last half of page 564 for an explanation.

Short answer:
1. Before chapter 22, we created a migration for the Django User model.
2. We then swapped the model with a custom User model.
3. The original migrations thus use a model that is no longer relevant.
4. We must therefore completely replace the initial migrations.

It is simply easiest to delete the database, rather than untangle the mess we've made. One of the conclusions of Chapter 22 is that swapping in a Custom User Model is best done at the beginning of a project. Swapping a custom user model on a project in production is outside the scope of the book.

> I followed your example, but got this error
>
> CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0002_profile, 0001_user in account). To fix them run 'python manage.py makemigrations –merge'
>
> What happened here? The only obvious difference between your examples and mine is the Python version, and I don't see how that's relevant here. It seems to be purely a Django migrations thing.

It is difficult for me to assess what went wrong without seeing any of your code and without any further information about what you've done.

All of the code in the book is available online.

https://github.com/jambonrose/DjangoUnleashed-1.8

If you perform a diff of your project and the code at commit 19560085fc in the repo above, what differences are there? If you run the migration command on the repo above, do you get the same error? I am unable to replicate your issue.

https://github.com/jambonrose/DjangoUnleashed-1.8/commit/19560085fc

On Jul 7, 2016, at 12:39 PM, Malik Rumi <malik....@gmail.com> wrote:
> raise ValueError("Could not find common ancestor of %s" % migration_names)
> ValueError: Could not find common ancestor of set([u'0002_profile', u'0001_user'])

This shows that there's something wrong with your migrations. How did you generate them? Did you delete the original ones first, as detailed on page 565? How does your project code compare to the book code online (see links above)?

> (cannon)malikarumi@Tetuoan2:~/Projects/cannon/jamf$ python manage.py make migrations account

It looks like you changed the name of the user domain to account (I assume this is the same as user; there is no account domain in the book). Are you also changing the name of the domain in the code and the commands in the book? If not, this may be causing problems.

Andrew
http://jambonsw.com
http://django-unleashed.com

Reply all
Reply to author
Forward
0 new messages