OperationalError at / no such table: users_user - python

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]

Related

AttributeError: 'postComments' object has no attribute 'model

I have made a new model postComments for my blogging website and now I am facing the above issue:
models.py:
from django.db import models
from django.contrib.auth.models import User
from django.utils.timezone import now
# Create your models here.
class post(models.Model):
SrNo = models.AutoField(primary_key=True)
title = models.CharField(max_length=50)
content = models.TextField()
author = models.CharField(max_length=50)
slug = models.SlugField(max_length=200)
timeStamp = models.DateTimeField(blank=True)
def __str__(self):
return self.title + " by " + self.author
class postComments(models.Model):
sno = models.AutoField(primary_key=True)
comment = models.TextField()
user = models.ForeignKey(User, on_delete=models.CASCADE)
post = models.ForeignKey(post, on_delete=models.CASCADE)
parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True)
timestamp = models.DateTimeField(default=now)
after writing the above '''postComments``` model the log window is showing me this error:
error log
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\jayant nigam\projects\practise\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\jayant nigam\projects\practise\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\jayant nigam\projects\practise\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\Users\jayant nigam\projects\practise\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\jayant nigam\projects\practise\lib\site-packages\django\contrib\admin\checks.py", line 54, in check_admin_app
errors.extend(site.check(app_configs))
File "C:\Users\jayant nigam\projects\practise\lib\site-packages\django\contrib\admin\sites.py", line 84, in check
if modeladmin.model._meta.app_config in app_configs:
AttributeError: 'postComments' object has no attribute 'model'
admin.py:
from django.contrib import admin
from blog.models import post, postComments
# Register your models here.
admin.site.register((post), (postComments))
urls.py(blog app):
from django.urls import path, include
from blog import views
urlpatterns = [
path('', views.blogHome, name='home'),
path('<str:slug>', views.blogPost, name='blogpost'),
# here blog_name is string variable which will take the input after /blog/anyblogname
# and after this the page will display: this is 'anyblogname'
]
before adding this new model, the website was working just fine.
The correct way to register models is one per register call
from django.contrib import admin
from blog.models import post, postComments
# Register your models here.
admin.site.register(post)
admin.site.register(postComments)

autocomplete fields in Django

Trying to set up autocomplete_fields in django.
I have following model:
from django.db import models
class Genre(models.Model):
title = models.CharField(max_length=255)
class Movie(models.Model):
title = models.CharField(max_length=255)
year = models.IntegerField()
time = models.CharField(max_length=255)
director = models.CharField(max_length=255)
genre = models.ManyToManyField(Genre)
image = models.ImageField(upload_to='images/')
actors = models.TextField()
summary = models.TextField()
admin.py:
from django.contrib import admin
from .models import Movie, Genre
class SettingAdmin(admin.ModelAdmin):
search_fields = ['genre']
class MovieAdmin(admin.ModelAdmin):
autocomplete_fields = ['genre']
admin.site.register(Movie, MovieAdmin)
admin.site.register(Genre)
Error Message:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "c:\users\ali\appdata\local\programs\python\python38\lib\threading.py", line 932, in _
bootstrap_inner
self.run()
File "c:\users\ali\appdata\local\programs\python\python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Ali\Desktop\cinemaEnv\lib\site-packages\django\utils\autoreload.py", line 53, in
wrapper
fn(*args, **kwargs)
File "C:\Users\Ali\Desktop\cinemaEnv\lib\site-packages\django\core\management\commands\runserver.py",
line 117, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Ali\Desktop\cinemaEnv\lib\site-packages\django\core\management\base.py", line 441, in
check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
<class 'movies.admin.MovieAdmin'>: (admin.E040) ModelAdmin must define "search_fields", because it's
referenced by MovieAdmin.autocomplete_fields.
i try this code with User model from django.contrib.auth.models and it worked.
i try this code with User model from django.contrib.auth.models and it worked.
As error msg said:
you need to define "search_fields" in Genre admin, since you use autocomplete_fields = ['genre'],
and don't forget to register Genre model with it.
class GenreAdmin(admin.ModelAdmin):
search_fields = ['title']
admin.site.register(Genre, GenreAdmin)

How correctly add permissions to User model of Django?

I am tring to add custom permissions to User model (django.contrib.auth.models).
To __init__.py file of my users app I add:
from django.db.models.signals import pre_migrate
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth import models as auth_models
from django.contrib.auth.models import Permission
from django.conf import settings
from django.dispatch import receiver
#receiver(pre_migrate, sender=auth_models)
def add_user_permissions(sender, **kwargs):
content_type = ContentType.objects.get_for_model(settings.AUTH_USER_MODEL)
Permission.objects.get_or_create(codename='view_user', name=' Can view users', content_type=content_type)
Permission.objects.get_or_create(codename='change_user_password', name=' Can change user password', content_type=content_type)
settings.py:
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.forms',
'django_select2', # "django-select2" application
'custom_app', # "custom_app" application
'custom_app_2', # "custom_app_2" application
'modeltranslation', # "django-modeltranslation" application
'users', # "users" application
]
ERROR:
Traceback (most recent call last):
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Applications/Projects/web/dashboard.kase.kz/users/__init__.py", line 5, in <module>
from django.contrib.contenttypes.models import ContentType
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 139, in <module>
class ContentType(models.Model):
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/db/models/base.py", line 110, in __new__
app_config = apps.get_containing_app_config(module)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/apps/registry.py", line 247, in get_containing_app_config
self.check_apps_ready()
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/apps/registry.py", line 125, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Question: How to fix this error?
Finally I found solution from documentation.
1) You need to create empty migration with next command:
python manage.py makemigrations --empty users
users - name of the app
2) Command create 0001_initial.py file where you need to put next code:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
def forwards_func(apps, schema_editor):
User = apps.get_model('auth', 'User')
Permission = apps.get_model('auth', 'Permission')
ContentType = apps.get_model('contenttypes', 'ContentType')
content_type = ContentType.objects.get_for_model(User)
db_alias = schema_editor.connection.alias
Permission.objects.using(db_alias).bulk_create([
Permission(codename='view_user', name=' Can view users', content_type=content_type),
Permission(codename='change_user_password', name=' Can change user password', content_type=content_type)
])
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.RunPython(forwards_func),
]
Please try adding this code at the top of the init.py file:
import django
django.setup()
copy all code in your init.py to a new created file called signals.py and change your __init__.py to :
default_app_config = 'user.apps.UserConfig'
signals.py
from django.db.models.signals import pre_migrate
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import AuthConfig
from django.contrib.auth.models import Permission
from django.conf import settings
from django.dispatch import receiver
#receiver(pre_migrate, sender=AuthConfig)
def add_user_permissions(sender, **kwargs):
content_type = ContentType.objects.get_for_model(settings.AUTH_USER_MODEL)
Permission.objects.get_or_create(codename='view_user', name=' Can view users', content_type=content_type)
Permission.objects.get_or_create(codename='change_user_password', name=' Can change user password', content_type=content_type)
then in user/apps.py:
from django.apps import AppConfig
class UserConfig(AppConfig):
name = 'user'
verbose_name = 'User'
def ready(self):
import user.signals
your error is occer because __init__.py will call User in models.py,but User model will be register after __init__.py run over,so you need call your signal when your User model is ready.
You want to add some perms related with User so:
class MyUser(User):
class Meta:
permissions = (
("view_user", "view_user"),
("change_user_password", "change_user_password"),
)
and in settings.py
AUTH_USER_MODEL = "user.MyUser"

django : LookupError: App ' doesn't have a 'models' model

I'm working through https://bixly.com/blog/awesome-forms-django-crispy-forms/ , trying to set up a bootstrap 3 form using django crispy forms.
in app1/models.py, I have set up my form:
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import AbstractUser
from django import forms
class User(AbstractUser):
# Address
contact_name = models.CharField(max_length=50)
contact_address = models.CharField(max_length=50)
contact_email = models.CharField(max_length=50)
contact_phone = models.CharField(max_length=50)
......
Please note I have not created any db tables yet. I don't need them at this stage. I'm just trying to get the forms working. When I run this I get:
Performing system checks...
Unhandled exception in thread started by <function wrapper at 0x02B63EF0>
Traceback (most recent call last):
File "C:\lib\site-packages\django\utils\autoreload.py", line 222, in wrapper
fn(*args, **kwargs)
File "C:\lib\site-packages\django\core\management\commands\runserver.py", line 105, in inner_run
self.validate(display_num_errors=True)
File "C:\lib\site-packages\django\core\management\base.py", line 362, in validate
return self.check(app_configs=app_configs, display_num_errors=display_num_errors)
File "C:\lib\site-packages\django\core\management\base.py", line 371, in check
all_issues = checks.run_checks(app_configs=app_configs, tags=tags)
File "C:\lib\site-packages\django\core\checks\registry.py", line 59, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\lib\site-packages\django\contrib\auth\checks.py", line 12, in check_user_model
cls = apps.get_model(settings.AUTH_USER_MODEL)
File "C:\lib\site-packages\django\apps\registry.py", line 202, in get_model
return self.get_app_config(app_label).get_model(model_name.lower())
File "C:\lib\site-packages\django\apps\config.py", line 166, in get_model
"App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'app1' doesn't have a 'models' model.
How can I fix this?
The AUTH_USER_MODEL settings should be of the form <app name>.<model>. Your model name is User, not model, so your setting should be:
AUTH_USER_MODEL = 'app1.User'
You should also remove the following User import from your models.py. You only have to import AbstractUser.
from django.contrib.auth.models import User

Customizing the Django User model - username as a Primary Key attribute

How to can I create my own user model in Django, in which I want that my P.K be the username field and not the id field autogenerated by Django?
I am trying the following:
I've create the userprofiles application in where I will create my customize django user model
INSTALLED_APPS = [
...
'userprofiles.apps.UserprofilesConfig',
...
]
AUTH_USER_MODEL = 'userprofiles.User'
In my userprofiles/models.py file I have defined the following:
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, UserManager, PermissionsMixin
# Create your models here.
class User(AbstractBaseUser, PermissionsMixin):
GENDER_MALE = 'M'
GENDER_FEMALE = 'F'
GENDER_OTHER = 'O'
GENDER_CHOICES = (
(GENDER_MALE, u'Male'),
(GENDER_FEMALE, u'Female'),
)
username = models.CharField(max_length=15, unique=True, db_index=True, primary_key=True)
first_name=models.CharField(max_length=50, blank=False,)
last_name=models.CharField(max_length=50, blank=False,)
photo = models.ImageField(upload_to='avatars', blank=True)
email = models.EmailField(max_length=254, unique=True)
is_staff = models.BooleanField(
default=True,
help_text='Designates whether the user can log into this admin site.')
is_active = models.BooleanField(default=True)
#date_joined = models.DateTimeField(default=None)
#date_joined = models.DateTimeField()
gender = models.CharField(
max_length=1,
choices=GENDER_CHOICES,
blank=False, )
is_player = models.BooleanField(default=False)
is_coach = models.BooleanField(default=False)
is_viewer = models.BooleanField(default=False)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email',]
objects = UserManager()
class Meta:
db_table = 'auth_user'
def get_full_name(self):
"""
Returns the first_name plus the last_name, with a space in between.
"""
full_name = '%s %s' % (self.first_name, self.last_name)
return full_name.strip()
def get_short_name(self):
"Returns the short name for the user."
return self.first_name
I am using the AbstractBaseUser class due to:
AbstractBaseUser provides the core implementation of a User model,
including hashed passwords and tokenized password resets. You must
then provide some key implementation details: ...
and also I considered this explanation in which say that is necessary add manually the fields that I needed.
Then, when I perform the migrations the fields that I've defined in my User model (that inherit from AbstractBaseUser) are created in my database:
(fuupbol) ➜ fuupbol_project git:(master) ✗ python manage.py makemigrations
Migrations for 'userprofiles':
0013_auto_20160418_2252.py:
- Add field groups to user
- Add field user_permissions to user
- Alter field is_superuser on user
(fuupbol) ➜ fuupbol_project git:(master) ✗ python manage.py migrate
Operations to perform:
Apply all migrations: sessions, userprofiles, admin, contenttypes, auth
Running migrations:
Rendering model states... DONE
Applying userprofiles.0013_auto_20160418_2252... OK
(fuupbol) ➜ fuupbol_project git:(master) ✗
Then I've created a superuser via command line interface of this way:
(fuupbol) ➜ fuupbol_project git:(master) ✗ python manage.py createsuperuser
Username: cdiaz
Email: cdiaz#fuupbol.org
Password:
Password (again):
Superuser created successfully.
(fuupbol) ➜ fuupbol_project git:(master) ✗
In addition, I add these fields of my custom User model for that Django Admin can view them, of this way:
Like Django use special forms to create and edit forms in the admin relative to Users model, due to these was thinked only for the django original user model.
Here we are using a custom django user model with AbstractBaseUser, then we use the following class:
UserChangeForm which is applied to the User model, so this way is applied to the admin user form, and the UserCreationForm for that an user be created with from my user form customized with the previous modifications
In my userprofiles/forms.py file
from django import forms
from django.contrib.auth.forms import (UserChangeForm,UserCreationForm)
from .models import User
class CustomUserChangeForm(UserChangeForm):
class Meta(UserChangeForm.Meta):
model = User
class CustomUserCreationForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = User
In my userprofiles/admin.py file create an CustomUserAdmin class customized with the fields defined before in my custom User model
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
from .forms import CustomUserChangeForm, CustomUserCreationForm
# Register your models here.
class CustomUserAdmin(UserAdmin):
form = CustomUserChangeForm
add_form = CustomUserCreationForm
fieldsets = UserAdmin.fieldsets + (
(
None, {
'fields':(
'username',
'password',
'first_name',
'last_name',
'gender',
'email',
'photo',
'is_staff',
'is_active',
'is_superuser',
'is_player',
'is_coach',
'is_viewer',
'last_login',
)
}
),
)
#Change our UserAdmin class to inherit of our CustomUserAdmin created above (do not inherit of model.ModelAdmin)
#admin.register(User)
class UserAdmin(CustomUserAdmin):
list_display = ('username','password','first_name','last_name','gender','email','photo','is_staff','is_active','is_superuser','is_player','is_coach','is_viewer','last_login',)
Then when I go to the Django admin and I see the options to edit some user already created, I get this message:
In this moment I do not have the date_joined attribute in my User model, and if I add the date_joined attribute to my User model, and perform the migrations, I get this messages:
(fuupbol) ➜ fuupbol_project git:(master) ✗ python manage.py makemigrations userprofiles
Migrations for 'userprofiles':
0022_user_date_joined.py:
- Add field date_joined to user
(fuupbol) ➜ fuupbol_project git:(master) ✗
And when I execute the migrate command
(fuupbol) ➜ fuupbol_project git:(master) ✗ python manage.py migrate userprofiles
Operations to perform:
Apply all migrations: userprofiles
Running migrations:
Rendering model states... DONE
Applying userprofiles.0015_user_date_joined...Traceback (most recent call last):
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
psycopg2.IntegrityError: column "date_joined" contains null values
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 "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/migrations/executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/migrations/migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
field,
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 396, in add_field
self.execute(sql, params)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 110, in execute
cursor.execute(sql, params)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/bgarcial/.virtualenvs/fuupbol/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: column "date_joined" contains null values
(fuupbol) ➜ fuupbol_project git:(master) ✗
I cannot understand the reason of the error message django.db.utils.IntegrityError: column "date_joined" contains null values due to in this moment I do not have this attribute date_joined
Any orientation would be appreciated.
Thanks
I am assuming you don't have data for date_joined on any of the instances and one of the migrations requires it to not be be null. You can probably either go into the database and add it manual to get around it temporarily.

Categories