Sunday, October 23, 2016

Re: Django Unleashed, custom user model

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.a.rumi@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.a.rumi@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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/58D045A1-6C79-4A99-8839-6D6D68AC8263%40andrewsforge.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment