Monday, December 21, 2015

Re: Error while customising Django User

Hi,

Thanks for your suggestion. Will try it out.

Thanks.

On Saturday, December 19, 2015 at 10:11:48 PM UTC+5:30, Abdoul Aziz Abdoulaye wrote:
Hello,
You can use django monkey patching for adding additional fields to User model

for your case it will look like this.

User.add_to_class('user_type', model.IntergerField())

Le vendredi 18 décembre 2015 11:55:16 UTC, Web Architect a écrit :
Hi,

I am new to Django and still under the process of learning. We are using an open source ecommerce platform - Oscar - for our online store. Oscar is based on Django.

I was trying to customise the Django User model by extending with some few extra fields/columns:

# file: your-project/apps/user/models.py  from django.db import models    
from django.contrib.auth.models import AbstractUser
class User(AbstractUser): user_type = models.IntegerField()
# use our own user model in settings.py  AUTH_USER_MODEL = "user.User"
With the above changes, when I run 'makemigration' followed by 'migrate', I am getting the following errors:

Running migrations:

  Rendering model states...Traceback (most recent call last):

  File "./manage.py", line 10, in <module>

    execute_from_command_line(sys.argv)

  File "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line

    utility.execute()

  File "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv

    self.execute(*args, **cmd_options)

  File "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute

    output = self.handle(*args, **options)

  File "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 222, in handle

    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)

  File "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/executor.py", line 100, in migrate

    state.apps  # Render all real_apps -- performance critical

  File "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/utils/functional.py", line 60, in __get__

    res = instance.__dict__[self.name] = self.func(instance)

  File "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/state.py", line 166, in apps

    return StateApps(self.real_apps, self.models)

  File "/Users/pinakeebiswas/waltzz/lib/python2.7/site-packages/django/db/migrations/state.py", line 248, in __init__

    raise ValueError(msg.format(field=operations[0][1], model=lookup_model))

ValueError: Lookup failed for model referenced by field basket.Basket.owner: customer.User


I am not sure what's causing the above error. Certainly there could be models which would be dependent on the User model but I thought the makemigrations and migrate should be able to resolve those.
Would appreciate if someone could help me with resolving the above errors.
Thanks

      

--
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/5b275610-c3af-40e2-9db7-f6ae36175e21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment