I successfully followed this tutorial and everything seemed to be ok. I then created a Profile model and managed to create it's objects through POST requests and through the admin panel. I then created signals so the profile could be created as soon as the user registered. After some trial and error I finally made it and decided I'd flush the database. When I tried to do so and ran python manage.py flush I got this error:
raise ValueError("Table %s does not exist" % table_name)
ValueError: Table allauth_socialapp does not exist
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\commands\flush.py", line 49, in handle
allow_cascade=allow_cascade)
File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\core\management\sql.py", line 16, in sql_flush
seqs = connection.introspection.sequence_list() if reset_sequences else ()
File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\db\backends\base\introspection.py", line 118, in sequence_list
sequence_list.extend(self.get_sequences(cursor, model._meta.db_table, model._meta.local_fields))
File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\db\backends\sqlite3\introspection.py", line 96, in get_sequences
pk_col = self.get_primary_key_column(cursor, table_name)
File "C:\Users\arthu\Desktop\dev\env\lib\site-packages\django\db\backends\sqlite3\introspection.py", line 196, in get_primary_key_column
raise ValueError("Table %s does not exist" % table_name)
ValueError: Table allauth_socialapp does not exist
I already tried doing python manage.py migrate for each of the installed apps but nothing seems to work and already tried removing the Profile model and the receiver it is using but that doesn't solve the problem. Also tried deleting the sqlite file and all the migrations but it didn't help.
My models.py file looks like this:
class Profile(models.Model):
GENDER_CHOICES = (
('Male', 'Male'),
('Female', 'Female')
)
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True)
interests = models.CharField(max_length=100, null=True)
gender = models.CharField(max_length=6, choices=GENDER_CHOICES, null=True)
def __str__(self):
return f"{self.user}'s Profile"
#receiver(user_signed_up)
def user_registered(sender, request, user, **kwargs):
print(f"Created profile for { user}")
Profile.objects.create(user=user)
"""Creates the Profile after user registers"""
and my settings.py file:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'django.contrib.sites',
'allauth',
'allauth.account',
'rest_auth.registration',
'core'
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
],
}
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
SITE_ID = 1
Can someone please help me with this? I have no idea what I'm supposed to do and couldn't really find the answer online.
Simply solved this by adding 'allauth.socialaccount' to my INSTALLED_APPS and doing the migrations. Everything works fine now.
Try python manage.py makemigrations AppName
If this didnt work you can delete migration folder and your database and try.
Related
I had a model Profile which was an extension to my User model which was the ForeignKey of my Post model, but I changed it to an AbstractUser and now if I try migrating or running and refreshing the page the server I get an error.
models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
bio = models.TextField(max_length=500,null=True)
from django.db import models
from django.conf import settings
from django.urls import reverse
class Post(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True)
title = models.CharField(max_length=100)
content = models.TextField()
def get_absolute_url(self):
return reverse('post-details', kwargs={'pk': self.pk})
settings.py
INSTALLED_APPS = [
...
'posts',
'users',
]
AUTH_USER_MODEL = 'users.User'
error message after I try migrating
Apply all migrations: admin, auth, contenttypes, posts, sessions, users
Traceback (most recent call last):
File "/home/user/Projects/DNF/Project/manage.py", line 22, in <module>
main()
File "/home/user/Projects/DNF/Project/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.10/dist-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 96, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/django/core/management/commands/migrate.py", line 295, in handle
pre_migrate_apps = pre_migrate_state.apps
File "/usr/local/lib/python3.10/dist-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.10/dist-packages/django/db/migrations/state.py", line 566, in apps
return StateApps(self.real_apps, self.models)
File "/usr/local/lib/python3.10/dist-packages/django/db/migrations/state.py", line 637, in __init__
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'users.user', but app 'users' doesn't provide model 'user'.
The field posts.Post.author was declared with a lazy reference to 'users.user', but app 'users' doesn't provide model 'user'.
The field users.Profile.user was declared with a lazy reference to 'users.user', but app 'users' doesn't provide model 'user'.
I easily solved it by deleting all the migration files in the migrations folder except the init.py file. And also delete db.sqlite3. Now run the following commands : python manage.py makemigrations and then python manage.py migrate. Now you'll have to create the super user once again, so for this just type the following commmand : python manage.py createsuperuser. Then it will prompt for username, email and password, so enter your credentials and all will continue to work properly once again I hope that this will be helpful.
try to directly reference the User model, not through settings
change the foreign key field to this:
author = models.ForeignKey("users.User", on_delete=models.CASCADE, null=True)
To have a reference to the User model, you should not do through settings directly instead you can use get_user_model() function. This function will return the currently active User model of project( the custom User model if one is specified, or User otherwise).
So change the foreign key field of your Post model like below:
from django.db import models
from django.conf import settings
from django.urls import reverse
from django.contrib.auth import get_user_model
User = get_user_model()
class Post(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
...
Reference: get_user_model() [Django-doc]
I need create custom user. I'm using a user model with AbstractUser:
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.html import escape, mark_safe
class User(AbstractUser):
is_student = models.BooleanField(default=False)
is_teacher = models.BooleanField(default=False)
settings.py:
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'crispy_forms',
'backend.classroom',
]
I believe that problem is in the following line:
AUTH_USER_MODEL = 'classroom.User'
error:
File "/home/davi/.local/share/virtualenvs/django-vue-template-Wl6a6m2J/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 82, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/davi/.local/share/virtualenvs/django-vue-template-Wl6a6m2J/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/davi/.local/share/virtualenvs/django-vue-template-Wl6a6m2J/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/davi/.local/share/virtualenvs/django-vue-template-Wl6a6m2J/lib/python3.6/site-packages/django/db/migrations/loader.py", line 226, in build_graph
self.add_external_dependencies(key, migration)
File "/home/davi/.local/share/virtualenvs/django-vue-template-Wl6a6m2J/lib/python3.6/site-packages/django/db/migrations/loader.py", line 191, in add_external_dependencies
parent = self.check_key(parent, key[0])
File "/home/davi/.local/share/virtualenvs/django-vue-template-Wl6a6m2J/lib/python3.6/site-packages/django/db/migrations/loader.py", line 173, in check_key
raise ValueError("Dependency on app with no migrations: %s" % key[0])
ValueError: Dependency on app with no migrations: classroom
obs: The app classrom app is in the backend folder. I tried the following code too:
AUTH_USER_MODEL = 'backend.classroom.User'
Try creating the initial migration for the classroom app before declaring it as AUTH_USER_MODEL, as anything that would ordinarily depend on auth.User now depends on classroom.User.
$ python manage.py makemigrations classroom
Your error is on the app install i think?
You are having classroom as app right? and the backend the project? if so then the correct
configuration
so the install app should be
INSTALLED_APPS = [
django.contrib.auth,
django.contrib.contenttypes,
django.contrib.sessions,
django.contrib.messages,
django.contrib.staticfiles,
django.contrib.humanize,
crispy_forms
classroom,
]
AUTH_USER_MODEL = classroom.User #classroom is app while User is the model
I am havnig troulble about migrating..I first tried
python manage.py migrate qablog
and didn't work. so I tried
python manage.py migrate qablog --fake-initial
and didn't work too.. so I googled again and some people were talking about changing the settings.py so I changed some things like changing USE_TZ to false ..
python manage.py makemigrations qablog
worked well though...can anyone help me with this? ..
python version: 3.4.4
mysql server version: 5.7
django version: 1.10.3
The error log is like below:
C:\inetpub\wwwroot\test>python manage.py migrate qablog --fake-initial
Operations to perform:
Apply all migrations: qablog
Running migrations:
Applying contenttypes.0001_initial... FAKED
Applying auth.0001_initial... OK
Applying qablog.0001_initial... OK
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
367, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 294,
in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 345,
in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py
", line 224, in handle
self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps,
plan=plan,
File "C:\Python34\lib\site-packages\django\core\management\sql.py", line 53, i
n emit_post_migrate_signal
**kwargs
File "C:\Python34\lib\site-packages\django\dispatch\dispatcher.py", line 191,
in send
response = receiver(signal=self, sender=sender, **named)
File "C:\Python34\lib\site-packages\django\contrib\auth\management\__init__.py
", line 83, in create_permissions
Permission.objects.using(using).bulk_create(perms)
File "C:\Python34\lib\site-packages\django\db\models\query.py", line 452, in b
ulk_create
ids = self._batched_insert(objs_without_pk, fields, batch_size)
File "C:\Python34\lib\site-packages\django\db\models\query.py", line 1068, in
_batched_insert
self._insert(item, fields=fields, using=self.db)
File "C:\Python34\lib\site-packages\django\db\models\query.py", line 1045, in
_insert
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python34\lib\site-packages\django\db\models\sql\compiler.py", line 10
53, in execute_sql
for sql, params in self.as_sql():
File "C:\Python34\lib\site-packages\django\db\models\sql\compiler.py", line 10
38, in as_sql
result.append(self.connection.ops.bulk_insert_sql(fields, placeholder_rows))
File "C:\Python34\lib\site-packages\mysql\connector\django\operations.py", lin
e 223, in bulk_insert_sql
return "VALUES " + ", ".join([items_sql] * num_values)
TypeError: can't multiply sequence by non-int of type 'tuple'
[manage.py]
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swingqa.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
[models.py]
from django.db import models
from django.utils import timezone
class Post(models.Model):
author = models.ForeignKey('auth.User')
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
and for the migration file.. I looked inside the qablog > migrations folder and there are init and 0001_initial file.. init file is empty (it's just blank inside) and 0001_ initial file is like below
[0001_initial.py]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2016-11-10 07:56
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)),
('text', models.TextField()),
('created_date', models.DateTimeField(default=django.utils.timezone.now)),
('published_date', models.DateTimeField(blank=True, null=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
I'd really appreciate for some help :-)
found a solution to this question by myself :-)
I don't really know the reason but
if you change operations.py file in this path below
C:\Python34\Lib\site-packages\mysql\connector\django
especially the part where def bulk_insert_sql function is,,from
def bulk_insert_sql(self, fields, num_values):
items_sql = "({0})".format(", ".join(["%s"] * len(fields)))
return "VALUES " + ", ".join([items_sql] * num_values)
to ...
def bulk_insert_sql(self, fields, placeholder_rows):
"""
Format the SQL for bulk insert
"""
placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
values_sql = ", ".join("(%s)" % sql for sql in placeholder_rows_sql)
return "VALUES " + values_sql
there will be no errors in doing python manage.py migrate qablog command.
TL;DR - Using django-custom-user and django-registration-redux, I am having trouble setting up a postgres database even on a virgin instance. It complains of a non-existent relationship, and I don't see why or where. The detail of the question below is not long but includes some error snippets that are moderately long. Any pointers much appreciated.
Using django-custom-user, I've learned that I must first make a migration for custom_user before the remaining migrations will work. Fair enough. On a clean instance (just created a database and git clone'd the code), I type
python manage.py makemigrations custom_user
python manage.py makemigrations
python manage.py migrate
But... no, I'm missing custom_user_emailuser. I suspect this means a relationship from custom_user on key emailuser, but I still find myself stumped on where this comes from and so what to do about it. Any tips much appreciated.
╭╴ (user-model-74=) [virt]╶╮
╰ [T] django#beta11:django $ python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: admindocs, kernel, messages, staticfiles, blog
Apply all migrations: custom_user, sites, auth, sessions, contenttypes, registration, admin
Synchronizing apps without migrations:
Creating tables...
Creating table blog_blogentry
Creating table kernel_userprofile
Creating table kernel_trippending
Running deferred SQL...
Traceback (most recent call last):
File "/src/django/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "custom_user_emailuser" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/src/django/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/src/django/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/src/django/venv/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/src/django/venv/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/src/django/venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/src/django/venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 317, in sync_apps
cursor.execute(statement)
File "/src/django/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/src/django/venv/lib/python3.4/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/src/django/venv/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/src/django/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "custom_user_emailuser" does not exist
╭╴ (user-model-74=) [virt]╶╮
╰ 1,[T] django#beta11:django $
which I don't understand, even worse because the custom_user migration doesn't call for such a thing:
╭╴ (user-model-74=) [virt]╶╮
╰ [T] django#beta11:django $ more venv/lib/python3.4/site-packages/custom_user/migrations/0001_initial.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('auth', '0006_require_contenttypes_0002'),
]
operations = [
migrations.CreateModel(
name='EmailUser',
fields=[
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_nam
e='ID')),
('password', models.CharField(verbose_name='password', max_length=128)),
('last_login', models.DateTimeField(null=True, blank=True, verbose_name='last login')),
('is_superuser', models.BooleanField(help_text='Designates that this user has all permiss
ions without explicitly assigning them.', verbose_name='superuser status', default=False)),
('email', models.EmailField(verbose_name='email address', unique=True, max_length=255, db
_index=True)),
('is_staff', models.BooleanField(help_text='Designates whether the user can log into this
admin site.', verbose_name='staff status', default=False)),
('is_active', models.BooleanField(help_text='Designates whether this user should be treat
ed as active. Unselect this instead of deleting accounts.', verbose_name='active', default=True)),
('date_joined', models.DateTimeField(verbose_name='date joined', default=django.utils.tim
ezone.now)),
('groups', models.ManyToManyField(related_name='user_set', to='auth.Group', help_text='Th
e groups this user belongs to. A user will get all permissions granted to each of their groups.', blank=T
rue, verbose_name='groups', related_query_name='user')),
('user_permissions', models.ManyToManyField(related_name='user_set', to='auth.Permission'
, help_text='Specific permissions for this user.', blank=True, verbose_name='user permissions', related_q
uery_name='user')),
],
options={
'abstract': False,
'verbose_name': 'user',
'swappable': 'AUTH_USER_MODEL',
'verbose_name_plural': 'users',
},
),
]
╭╴ (user-model-74=) [virt]╶╮
╰ [T] django#beta11:django $
It turns out that custom_user must be migrated before the rest of the world, but sites even before custom_user. So this solved our problem:
python manage.py migrate sites
python manage.py migrate custom_user
python manage.py migrate
Getting this error when running python manage.py migrate:
ValueError: Lookup failed for model referenced by field account.UserProfile.user: auth.User
Steps I did:
1. Created project and added new app:
$ django-admin.py startproject djdev
$ cd djdev
$ python manage.py startapp account
2. I added new app to INSTALLED_APPS in djdev/settings.py:
...
'django.contrib.staticfiles',
'account',
)
...
3. Created a new UserProfile model class in account/models.py:
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
"""
User Profile having one-to-one relations with User
"""
class Meta:
db_table = 'user_profile'
ordering = ['id']
user = models.OneToOneField(User, db_column='id_user', related_name='profile')
mobile_no = models.CharField('Mobile no.', db_column='contact_no_home', max_length=16, blank=True, null=True)
address_line_1 = models.CharField('Address Line 1', db_column='contact_address_line_1_home', max_length=140, blank=True, null=True)
address_line_2 = models.CharField('Address Line 2', db_column='contact_address_line_2_home', max_length=140, blank=True, null=True)
office_mobile_no = models.CharField('Mobile no.', db_column='contact_no_office', max_length=16, blank=True, null=True)
office_address_line_1 = models.CharField('Address Line 1', db_column='contact_address_line_1_office', max_length=140, blank=True, null=True)
office_address_line_2 = models.CharField('Address Line 2', db_column='contact_address_line_2_office', max_length=140, blank=True, null=True)
about = models.TextField('About me', blank=True, null=True)
note = models.CharField('Note', max_length=255, blank=True, null=True)
def __unicode__(self):
return self.user.name
4. Started migrating:
$ python manage.py makemigrations account
$ python manage.py migrate
After executing last command python manage.py migrate I'm getting this error:
Operations to perform:
Synchronize unmigrated apps: (none)
Apply all migrations: admin, contenttypes, account, auth, sessions
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying account.0001_initial...Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vinay/python_webapps/django-trunk/django/core/management/__init__.py", line 427, in execute_from_command_line
utility.execute()
File "/home/vinay/python_webapps/django-trunk/django/core/management/__init__.py", line 419, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vinay/python_webapps/django-trunk/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/vinay/python_webapps/django-trunk/django/core/management/base.py", line 337, in execute
output = self.handle(*args, **options)
File "/home/vinay/python_webapps/django-trunk/django/core/management/commands/migrate.py", line 146, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/home/vinay/python_webapps/django-trunk/django/db/migrations/executor.py", line 62, in migrate
self.apply_migration(migration, fake=fake)
File "/home/vinay/python_webapps/django-trunk/django/db/migrations/executor.py", line 90, in apply_migration
if self.detect_soft_applied(migration):
File "/home/vinay/python_webapps/django-trunk/django/db/migrations/executor.py", line 134, in detect_soft_applied
apps = project_state.render()
File "/home/vinay/python_webapps/django-trunk/django/db/migrations/state.py", line 83, in render
model=lookup_model
ValueError: Lookup failed for model referenced by field account.UserProfile.user: auth.User
NOTE: Django Version I'm using: 1.8.dev20140507130401
This is already fixed in the master branch.
Fixed in commits:
https://code.djangoproject.com/changeset/8f6dff372b174e772920de6d82bd085f1a74eaf2
https://code.djangoproject.com/changeset/35c2a14a49ac3cb25dcff818b280bf0b4c290287
You can install it until a proper release is built:
pip install https://github.com/django/django/zipball/master
Test:
models.py
from django.db import models
from django.contrib.auth.models import User
class Test(models.Model):
user = models.OneToOneField(User)
Results
[__env] $ ./manage.py makemigrations
Migrations for 'data':
0001_initial.py:
- Create model Test
[__env] $ ./manage.py migrate
Operations to perform:
Synchronize unmigrated apps: admin, contenttypes, auth, sessions
(... ommited ...)
Running migrations:
Applying data.0001_initial... OK
I read the comment above as suggesting adding only the last line in the dependencies list (('contenttypes',' __first__')), but I had to add the last two to correct the problem. This might be obvious to those with a better understanding of the makemigrations tool in Django, but I am new to it and it was not to me.
My last migrations file dependencies list that was originally giving the same error...
dependencies = [
('myapp', '0006_auto_20150209_0324'),
(b'auth', b'__first__'),
(b'contenttypes', b'__first__'),
]
I've found another solution that also work fine.
See the solution of by rockallite.wulf#
https://code.djangoproject.com/ticket/22488
Just add the corresponding dependency in the migration file, like this:
dependencies = [
(b'advperm', b'0001_initial'),
(b'auth', b'__first__'),
(b'contenttypes', b'__first__'), # Add this line
]