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
Related
For a number of reasons, running from unit testing performance to migration issues (Django Migration Error: Column does not exist), I have found it useful to turn the debug toolbar on and off.
Here's a way I've found to control loading it from environment variables.
No, not really a question, think of it as a recipe that I wish I had found on SO.
I believe putting
def show_toolbar(request):
if DEBUG:
return True
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK": show_toolbar,
}
in settings.py is the recommended way and perhaps a bit simpler?
settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#conditionally disable later on
'debug_toolbar',
#...my apps...
)
#disable if not in DEBUG or if $USE_DEBUG_TOOLBAR is not set.
USE_DEBUG_TOOLBAR = bool(int(os.getenv("USE_DEBUG_TOOLBAR", 0))) and DEBUG
#disable as well if running unit tests...
pgm = os.path.basename(sys.argv[0])
if not USE_DEBUG_TOOLBAR or pgm.startswith("test") or pgm.startswith("nosetests"):
li = [app for app in INSTALLED_APPS if not app == "debug_toolbar"]
INSTALLED_APPS = tuple(li)
and your command line use might look like:
export USE_DEBUG_TOOLBAR=1 && python manage.py runserver
I am trying to use django-threadedcomments app to allow comments in my website following the configurations mentioned https://pypi.python.org/pypi/django-threadedcomments. my installed apps are
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# for comments
'threadedcomments'
'django_comments',
'django.contrib.sites',
# installed apps
# APPS
'debug_toolbar',
#related to debug_toolbar
'haystack_panel',
'whoosh',
'haystack',
'taggit',
'question',
]
COMMENTS_APP = 'threadedcomments'
After adding the 'threadedcomments' app in the settings.py I am gettting the error when I run python manage.py migrate or python manage.py runserver
ImportError: No module named threadedcommentsdjango_comments
Full Error Trace
however the code works fine without 'threadedcomments' and with 'django_comments'.
I am using django 1.8.8 and posgres9.5. please help.
note:
I have already installed 'threadedcomments' app in my venv.
OK, In your settings you are missing ','(comma):
'threadedcomments'
'django_comments',
===>
'threadedcomments',
'django_comments',
If you were accurate you can find that in your own screen:
No module named threadedcommentsdjango_comments
there is no split between two packages.
I deployed my Django project to Heroku. Now, I want to add another app to my existing project. How can I do it in a way that a new database is not created- I mean my existing database should not get deleted?
You can just run heroku run python manage.py syncdb after pushing your new app with model definitions. This won't delete your database. Consider installing South though.
Using PyPI
If the app you want to install is available on the Python Package Index, you can add the name of the add and the version you want to use in your requirements.txt file like:
app_name==1.2.3
Then, in your project/settings.py file, add the app_name as a string to the list of INSTALLED_APPS. For instance, if INSTALLED_APPS looks like this:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
then adding the new app will make it:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'package_name',
)
Using git
You can follow the same steps as above, but instead of adding app_name==1.2.3, you add:
git+git://github.com/owner_name/app_name#egg=app_name
replacing owner_name and app_name appropriately. This clones the repository that you point to, so be sure that it's either public or that you have ssh access if it's private.
I'm been trying to install celery for a couple of days and the problem , I'm facing is . when I try to do manage.py syncd . I get the error message .
C:\o\17\mysite>manage.py syncdb
Error: No module named djcelery
When I already successfully installed the celery using easy_install
C:\o\17\mysite>easy_install django-celery
Searching for django-celery
Best match: django-celery 3.0.17
Processing django_celery-3.0.17-py2.6.egg
django-celery 3.0.17 is already the active version in easy-install.pth
Installing djcelerymon script to C:\Python26\Scripts
Installing djcelerymon-script.py script to C:\Python26\Scripts
Installing djcelerymon.exe script to C:\Python26\Scripts
Installing djcelerymon.exe.manifest script to C:\Python26\Scripts
Using c:\python26\lib\site-packages\django_celery-3.0.17-py2.6.egg
Processing dependencies for django-celery
Finished processing dependencies for django-celery
I already set up my broker which is the django database i'm using.
BROKER_URL = 'django://'
I added djcelery to installed_app
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'pet',
'kombu.transport.django',
'djcelery ',
)
I also added the following lines to my setting.py
import djcelery
djcelery.setup_loader()
I have experience in installing django plugins before , I just don't understand why this won't let me syncdb at cmd
What am I doing wrong? Can someone please help me :)
I think the problem is with a space char at the end of djcelery in INSTALLED_APPS. Try to remove it and run syncdb again. Hope that helps.
Try:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'pet',
'kombu.transport.django',
'djcelery ',
)
I am working on this Django tutorial and am getting this error: "Error: No module named polls" when I type "python manage.py sql polls" in the terminal. I have no clue how to fix this problem. Any help would be greatly appreciated.
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'polls' # THIS IS THE ANSWER
)
There is an error in the documentation. Type polls instead of mysite.polls.
Ismael's answer worked for me.
Originally had
urlpatterns = patterns('',
(r'^polls/$ ,'mysite.polls.views.index'),
)
Changed to
urlpatterns = patterns('',
(r'^polls/$ ,'polls.views.index'),
)
If you have added polls app inside the setting.py please remove that and try recreating the polls and then add to the setting.py file. This solved my issue :)
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#Remove the below application and try again
#'polls',
)
It might be possible that you missing "," after 'polls.apps.PollsConfig' in settings.py file
This need to run one command after your changes in INSTALLED_APPS
$ python manage.py makemigrations polls
after that:
$ python manage.py sqlmigrate polls 0001
You must create all these files in pool directory: init.py, admin.py, models.py, tests.py,views.py.
succes
Be sure you actually stayed true to the tutorial and named your app "polls", otherwise things won't link up.
Changing from 'polls.app.PollsConfig' to 'polls' worked for me