I am working on the Django model. I migrate all the files of the app, but it is showing me the model doesn't have migrations and also no migration file in the folder, but init.py file exists in the folder.
Please give me suggestions.
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
[X] 0009_alter_user_last_name_max_length
[X] 0010_alter_group_name_max_length
[X] 0011_update_proxy_permissions
[X] 0012_alter_user_first_name_max_length
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial
First delete your all migrations folder and try below command:
python manage.py makemigrations appname
python manage.py sqlmigrate appname 0001 #This value will generate after makemigrations
python manage.py migrate
I have been having challenges with my migrations from local to heroku. It appears that the schemas are out of sync.
Here is my local database schema from python manage.py showmigrations
account
[X] 0001_initial
[X] 0002_email_max_length
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
[X] 0009_alter_user_last_name_max_length
[X] 0010_alter_group_name_max_length
[X] 0011_update_proxy_permissions
[X] 0012_alter_user_first_name_max_length
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial
sites
[X] 0001_initial
[X] 0002_alter_domain_unique
socialaccount
[X] 0001_initial
[X] 0002_token_max_lengths
[X] 0003_extra_data_default_dict
testingland
[X] 0001_initial
Here is the heroku schemas from heroku run python manage.py showmigrations
account
[X] 0001_initial
[X] 0002_email_max_length
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
[X] 0009_alter_user_last_name_max_length
[X] 0010_alter_group_name_max_length
[X] 0011_update_proxy_permissions
[X] 0012_alter_user_first_name_max_length
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial
sites
[X] 0001_initial
[X] 0002_alter_domain_unique
socialaccount
[X] 0001_initial
[X] 0002_token_max_lengths
[X] 0003_extra_data_default_dict
I believe the problem stems from deleting the migrations folder in my testingland app earlier. I ran python3 manage.py makemigrations testingland and the migrations folder came back but when I run:
python manage.py makemigrations
git commit -a
git push heroku main
I just get Everything up-to-date and when I try to do anything in my heroku app I get this problem or something similar meaning the testingland app and schemas aren't available there:
ProgrammingError at /api/liked/
relation "testingland_liked" does not exist
LINE 1: ...er_id", "testingland_liked"."liked_venue_id" FROM "testingla...
Here are the installed apps in my settings.py file:
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',
# all auth
# The following apps are required:
# 'django.contrib.auth',
# 'django.contrib.messages',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'widget_tweaks',
]
I have tried to be as clear as possible with this question - I am desperate for a solution.
I am going to make a very simple Restful API. So there is no reason to use the default tables in Django.
auth_group
auth_group_permissions
auth_permission
django_admin_log
etc..
Is it possible to define and use only the model (table) I want without using the default tables provided by Django?
remove the auth and admin application from your INSTALLED_APPLICATION list from your settings.py.
INSTALLED_APPS = [
'django.contrib.admin', # remove this line
'django.contrib.auth', # as well as this
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
And do a fresh migration on the database.
python manage.py makemigrations
python manage.py migrate
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 currently have a django app am developing on my PC with data in my db but when i try running this app on a test server i get the error below
DatabaseError: relation "django_site" does not exist
LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
can any one tell me why am getting this error please.thanks
You may be calling a site object before creating site model(before syncdb)
ex: site = Site.objects.get(id=settings.SITE_ID)
This issue continues to plague many, including myself. Although a tedious process, this approach saves me the brain power:
Disable all external apps in your INSTALLED_APPS, except your own apps, like so:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.flatpages',
'main', # This is my own app.
# 'compressor',
# 'ckeditor',
# 'imagekit',
# 'debug_toolbar',
# 'rest_framework',
# 'allauth',
# 'allauth.account',
# 'allauth.socialaccount',
# 'allauth.socialaccount.providers.google',
# 'allauth.socialaccount.providers.facebook',
)
Run
python manage.py makemigrations
python manage.py migrate
Then, uncomment all the other apps, then repeat makemigrations and migrate above.
That works all the time for me
I can't see your models or what apps are you using, but my guess is that you are using django_site (Site model) and you don't have 'django.contrib.sites' in the INSTALLED_APPS.
If I'm correct then just add 'django.contrib.sites', to your INSTALLED_APPS.
Had this strange issue while initiating a new database and using django-debug-toolbar. Removed it from the INSTALLED_APPS and was able to run syncdb. Then re-added debug_toolbar and it was still working fine.
If you're using django-debug-toolbar, try to comment out debug_toolbar in your installed apps and try again.
Update: Please follow the steps for the explicit setup: http://django-debug-toolbar.readthedocs.org/en/1.2.2/installation.html#explicit-setup
i have same problem and fixed it like this:
add SITE_ID=1 into settings.py
run this command :
python manage.py migrate
not been able to solve this a django way so i tried using sql, i created a dump of just the database like this.
pg_dump mypgdatabase | gzip -c > mypgdatabase.dump.out.gz
then moved it to the server
scp /path/to/mypgdatabase.dump.out.gz my_remote_server
then recreated it on the server like this
psql -d mypgdatabase -f mypgdatabase.dump.out
then run
./manange.py migrate --all
and all when well.
Couple of things you can try and check:
Your settings.py should have a SITE_ID usually = 1
Change order of your INSTALLED_APPS in your settings.py and try temporarily commenting items out.
As Geo said, check that you're not calling a site object before creating site model (ex: site = Site.objects.get(id=settings.SITE_ID)).
Once you got it working, remember to manage.py makemigrations APP_NAME as I found cases where it seem to have then avoided the commenting out step.
I overcame this issue with the following order in INSTALLED_APPS:
INSTALLED_APPS = (
'django.contrib.sites',
'allauth',
'allauth.account',
# my other apps,
)
My "commenting out" pattern was slightly different than the accepted answers (as shown below). That is to say, it might be unique depending on the values of various dependencies scattered throughout your app. If commenting out the values above throws an error message, I recommend commenting out the apps that throw the error message and uncommenting accordingly until it works for you. This may be a little "brute force" but it should get the job done.
INSTALLED_APPS = [
# django native apps
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
"django.forms",
'django.contrib.gis',
# 'django.contrib.flatpages',
#third party apps
#django-allauth apps
'allauth',
# 'allauth.account',
# 'allauth.socialaccount',
# 'allauth.socialaccount.providers.facebook',
# 'allauth.socialaccount.providers.google',
# 'allauth.socialaccount.providers.twitter',
# 'allauth.socialaccount.providers.github',
# my apps
'app0',
'app1',]
#MIGRATION_MODULES = {"sites": "mysite.contrib.sites.migrations"}
Also make sure SITE_ID = 1 comes before the DATABASE definition in settings.py