The table wasn't created when I made custom user model.
In my settings.py, I installed my app and defined AUTH_USER_MODEL
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
#My apps
'accounts',
]
AUTH_USER_MODEL = 'accounts.User'
my model is below (at accounts app)
class User(AbstractBaseUser):
key = models.AutoField(primary_key=True)
email= models.EmailField('email',unique=True)
name=models.CharField('name',max_length=20) #model.USERNAME_FIELD
is_active=models.BooleanField('is_active',default=True)
is_admin=models.BooleanField('is_admin',default=False)
date_joined = models.DateTimeField('date_joined',default=timezone.now)
objects = UserManager()
USERNAME_FIELD = 'email'
#EMAIL_FIELD = 'email'
class Meta:
swappable = "AUTH_USER_MODEL"
I executed makemigrations && migrate.
And I've also tried makemigrations accounts && migrate accounts
but still there is no accounts_user table.
Step-1 delete migration folder
Step-2 run command (python manage.py makemigrations your app name
Step -3 run command (python manage.py migrate)
If still not working...??
repate above steps
but this time also deleted sqlite3 database
Related
I have a installed an app called 'Login', who have a folder 'models' inside, with a custom_user model. The problem occurs when I tried to configure settings.py, specially auth_user_model.
in installed apps I have the following:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'project_app.login'
]
and below
AUTH_USER_MODEL = 'login.models.CustomUser'
But I have the following error: "Invalid model reference. String model references must be of the form 'app_label.ModelName'." I put the .models in AUTH_USER_MODEL, because I want to reference the app that the CustomUser is inside the folder "models" in Login.
Also, I tried with declare like this:
AUTH_USER_MODEL = 'login.CustomUser'
but the error is this: 'AUTH_USER_MODEL refers to model 'login.CustomUser' that has not been installed'
The issue is with the way that your app is installed - based on your AUTH_USER_MODEL, login should be the name of the app. It is acceptable to contain Django apps within folders for organisation purposes - however, your parent folder is project_app which from the name also appears to be an app. It's hard to say for certain what the issue is without knowing your project structure but I would expect changing your installed apps to just project_app and your AUTH_USER_MODEL to project_app.CustomerUser should work.
If your app name is "login", you can proceed as follows:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
#apps
'login.apps.LoginConfig']
I think the model in your login application is as follows:
class CustomUser(AbstractBaseUser):
#some fields for customuser
and in settings.py:
AUTH_USER_MODEL = 'user.CustomUser'
AUTH_USER_MODEL = 'app_name.ModelName'
New to heroku - I had some major problems with a migration from my local django app to Heroku prod so decided to destroy my heroku db with heroku pg:reset - this all seemed to go to plan, I then ran heroku run python manage.py migrate to attempt to recreate my schemas.
The following were migrated:
Apply all migrations: account, admin, auth, contenttypes, sessions, sites, socialaccount
But none of my models.py tables went up - eg the following crucial schema was not migrated:
class mapCafes(models.Model):
id = models.BigAutoField(primary_key=True)
cafe_name = models.CharField(max_length=200)
cafe_address = models.CharField(max_length=200)
cafe_long = models.FloatField()
cafe_lat = models.FloatField()
geolocation = models.PointField(geography=True, blank=True, null=True)
venue_type = models.CharField(max_length=200)
source = models.CharField(max_length=200)
cafe_image_url = models.CharField(max_length=200, null=False)
# class Meta:
# # managed = False
def __str__(self):
return self.cafe_name
Installed Apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'testingland',
'rest_framework',
'bootstrap_modal_forms',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'widget_tweaks',
]
Any advice?
I am unable to replace default django user model with my own custom user model.
yes, i have AUTH_USER_MODEL = 'appName.modelName' set in settings.py
here's my code
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'userProfile',
'user_authorisation',
]
AUTH_USER_MODEl = 'userProfile.myUser'
userProfile/models.py
https://dpaste.de/Aerm
userProfile.forms.py https://dpaste.de/0eOO
userProfile/admin.py https://dpaste.de/Rm5S
After all this, Default user model is still showing in django admin
and also, when creating super user via the command python manage.py createsuperuser , it is creating the super user of the default user model.
It's typo in your settings AUTH_USER_MODEl, should be AUTH_USER_MODEL instead.
I've been trying to create a custom user to store extra fields in Django, but after specifying the new User and deleting the old database, Django does not want to make a table or any migrations for my app "accounts"
Error (when doing anything user related e.g. logging in):
django.db.utils.OperationalError: no such table: accounts_user
Auth User Model in settings.py:
AUTH_USER_MODEL = 'accounts.User'
Installed apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
'forum',
]
accounts/models.py:
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
pass
Edit:
I apologize, I forgot to mention. I have run makemigrations and migrate.
Makemigrations returns "No changes detected." Migrate does everything but any models existing in my accounts/models.py
Turns out I had to specifically run "makemigrations accounts". Not sure why, but it worked.
I am trying to customize Products and few other models in the catalogue app following the documentation.
I have forked catalogue app (to myproject/boscar/catalogue) as per documentation documentation and my updated boscar/catalogue/models.py:
from django.db import models
from oscar.apps.catalogue.abstract_models import AbstractProduct
class Product(AbstractProduct):
is_active = models.BooleanField(default=False)
from oscar.apps.catalogue.models import *
I have already included the modified catalogue app, in the INSTALLED_APPS in settings.py as an argument for get_core_apps function.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'django.contrib.sites',
'django.contrib.flatpages',
'bmigrate',
'compressor',
'widget_tweaks',
'boscar'
] + get_core_apps(['boscar.catalogue'])
Migrations are automatically copied to my local app when I executed this command manage.py oscar_fork_app catalogue boscar.
My issue is when I execute the makemigrations command (python "manage.py makemigrations boscar"), it shows "No changes detected in app 'boscar'". But I already made a change to add is_active field in product table.
I believe you need to refer to the catalogue app when migrating:
python manage.py makemigrations catalogue