Reset Heroku DB now some of my schemas aren't migrating - django

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?

Related

Table wasn't created when making custom user model

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

OperationalError at /admin/app/question/ no such table: app_question (django)

Im new to this and Im tryna make a q&a type of app, I was just starting then when I went to admin/ to try it out I got
OperationalError at /admin/app/question/
no such table: app_question
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/app/question/
Django Version: 4.0.1
Python Version: 3.10.1
Installed Applications:
['app',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'crispy_forms',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'users']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Exception Type: OperationalError at /admin/app/question/
Exception Value: no such table: app_question
here is the models.py
from django.db import models
from django.contrib.auth.backends import ModelBackend
from users.models import CustomUser
# This is the question model
class Question(models.Model):
user = models.ForeignKey('users.CustomUser', on_delete=models.CASCADE)
title = models.CharField(max_length=30)
detail = models.TextField()
add_time = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
# This is the answer model
class Answer(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
detail = models.TextField()
add_time = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.detail
I'd appreciate if its explained in a beginner friendly manner, thank you!
Here is the documentation. You should
run migrate again to create those model tables in your database:

Django can't load ckeditor in the admin page

This is my settings.py file
INSTALLED_APPS = [
'search.apps.SearchConfig',
'user.apps.UserConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django_node_assets',
'ckeditor',
'ckeditor_uploader',
]
CKEDITOR_BASEPATH = "./search/static/ckeditor/ckeditor/"
CKEDITOR_UPLOAD_PATH = "/media/"
This is the models.py file
from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField
class Content(models.Model):
heading = models.ForeignKey(SubTopics, on_delete=models.CASCADE)
content = RichTextField()
def __str__(self):
return self.heading.heading
This rich text editor is not showing on the admin page. Even no text field is shown on the page, just blank space.
I got the solution.
remove CKEDITOR_BASEPATH and it will work
you need to collect the static files. Use the command below in the terminal
python manage.py collectstatic

django oscar model customization : model change is not reflected while makemigrations

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

Django CMS 3.1.3, Python 3.4 and Django 1.8 CustomUser

I have found similar post but none of the answers helped me. I'm getting a "LookupError: Model 'email_user.EmailUser' not registered." when trying to run a makemigrations or migrate. Any help or suggestions would be greatly appreciated.
ProjectStructure
ProjectRoot/
- email_user/
-- __init__.py
-- admin.py
-- models.py
- djangocms/
-- static/
-- templates/
-- __init__.py
-- urls.py
- manage.py
- settings.py
- wsgi.py
settings.py
INSTALLED_APPS = (
'djangocms_admin_style',
'djangocms_text_ckeditor',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'django.contrib.messages',
'email_user',
'cms',
'menus',
'sekizai',
'treebeard',
'djangocms_style',
'djangocms_column',
'djangocms_file',
'djangocms_flash',
'djangocms_googlemap',
'djangocms_inherit',
'djangocms_link',
'djangocms_picture',
'djangocms_teaser',
'djangocms_video',
'reversion',
'djangocms',
)
AUTH_USER_MODEL = "email_user.EmailUser"
email_user/admin.py
from django.contrib import admin
from email_user.models import EmailUser
admin.site.register(EmailUser)
email_user/models.py
class EmailUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField('email address', max_length=255, unique=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
def get_short_name(self):
return self.email
def get_full_name(self):
return self.email
Ugh,
After hours of digging around I tracked down the problem. The Django CMS Installer will automatically setup the settings.py file for you and the INSTALLED_APPS area.
So for some reason some of the dependencies are not setup correctly and following the documentation will result in hours of banging your head on the table.
The Installed apps should look like this:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'djangocms_admin_style', # MOVED THIS HERE
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'django.contrib.messages',
'email_user',
'djangocms_text_ckeditor', # MOVED THIS HERE
'cms',
'menus',
'sekizai',
'treebeard',
'djangocms_style',
'djangocms_column',
'djangocms_file',
'djangocms_flash',
'djangocms_googlemap',
'djangocms_inherit',
'djangocms_link',
'djangocms_picture',
'djangocms_teaser',
'djangocms_video',
'reversion',
'securepal',
)
Hopefully this might save someone from having to track this down