Foreign key User on migration‏

335 views
Skip to first unread message

Sam Contapay

unread,
Aug 4, 2014, 11:06:00 AM8/4/14
to django...@googlegroups.com
Hi,

I tried adding a foreign key to a model in a Django app I'm building to learn 1.7. I am using Python 3.4 and Django 1.7c2

#blog/models.py

from django.contrib.auth.models import User
from django.db import models

class Comment(models.Model):
    user = models.ForeignKey(User, blank=True, null=True)
    created_at = models.DateTimeField(auto_now=True)
    comment = models.CharField(max_length=255)

This is an already existing database I ran "manage.py makemigrations" and "manage.py migrate". Make migration works fine but running migrate generates this error (I am not using a custom user model). I don't understand 'auth' not found as it is in my project settings and I am using the admin panel:

(screens)➜  screens git:(master ./manage.py migrate

Operations to perform:

  Synchronize unmigrated apps: django_extensions, crispy_forms

  Apply all migrations: auth, admin, contenttypes, sessions, website

Synchronizing apps without migrations:

  Creating tables...

  Installing custom SQL...

  Installing indexes...

Running migrations:

  Applying website.0004_comment_created_by_user...Traceback (most recent call last):

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/apps/registry.py", line 148, in get_app_config

    return self.app_configs[app_label]

KeyError: 'auth'


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/db/migrations/state.py", line 79, in render

    model = self.apps.get_model(lookup_model[0], lookup_model[1])

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/apps/registry.py", line 202, in get_model

    return self.get_app_config(app_label).get_model(model_name.lower())

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/apps/registry.py", line 150, in get_app_config

    raise LookupError("No installed app with label '%s'." % app_label)

LookupError: No installed app with label 'auth'.


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

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

    execute_from_command_line(sys.argv)

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line

    utility.execute()

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute

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

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv

    self.execute(*args, **options.__dict__)

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/core/management/base.py", line 337, in execute

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

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 160, in handle

    executor.migrate(targets, plan, fake=options.get("fake", False))

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/db/migrations/executor.py", line 63, in migrate

    self.apply_migration(migration, fake=fake)

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/db/migrations/executor.py", line 91, in apply_migration

    if self.detect_soft_applied(migration):

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/db/migrations/executor.py", line 135, in detect_soft_applied

    apps = project_state.render()

  File "/Users/scontapay/.pyenv/versions/screens/lib/python3.4/site-packages/django/db/migrations/state.py", line 89, in render

    model=lookup_model,

ValueError: Lookup failed for model referenced by field website.Comment.created_by_user: auth.User

Sam Contapay

unread,
Aug 4, 2014, 11:20:02 PM8/4/14
to django...@googlegroups.com
I downloaded the latest code from stable/1.7.x branch and this problem no longer exists.
Reply all
Reply to author
Forward
0 new messages