I am trying to setup multiple sites from a single project in django. I was trying to set this up following https://docs.djangoproject.com/en/1.8/ref/contrib/sites/ but there is no mention of setup only how to use the sites framework once implemented.
I have implmented sites before and I added sites to my installed apps like this:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
)
I tried to issue the command: python manage.py makemigrations but it says:
No Changes detected
I'm using django 1.8 , does the sites framework setup still create a table called django_site ?
How do I do the initial setup to have this table created?
I guess I needed to just migrate instead of make migrate like this:
python manage.py migrate
Related
I am facing this problem with migrating in Django admin after I updated the app name 'rest_framework.authtoken' in django project settings.
It gives me error The model TokenProxy is already registered in app 'authtoken'.
I know I should have added this and migrate before creating super user but now I have already created the project and migrated lots of models and there is a data in it. Can help me how I can resolve this problem.
I also tried to undo migrations with command python manage.py migrate books but it again does not recognize the word books.
Please help me with this.
Here is my apps in settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
'traderskamp_app',
'rest_framework.authtoken',
'rest_framework',
'corsheaders',
]
Here is the exact error:
File "C:\Python39\lib\site-packages\rest_framework\authtoken\admin.py", line 51, in
admin.site.register(TokenProxy, TokenAdmin)
File "C:\Users\Anwar\AppData\Roaming\Python\Python39\site-packages\django\contrib\admin\sites.py", line 126, in register
raise AlreadyRegistered(msg)
django.contrib.admin.sites.AlreadyRegistered: The model TokenProxy is already registered in app 'authtoken'.
might be a bit late but I would search your project for this.
admin.site.register(TokenProxy)
you are likely registering TokenProxy somewhere in your code and that is causing a conflict with authtoken
I am trying to start a new project on djago in google colab. I have created new project and also pasted-
ALLOWED_HOSTS = ['colab.research.google.com','*'] to settings.py.
And using this:
from google.colab.output import eval_js
print(eval_js("google.colab.kernel.proxyPort(8000)"))
to get the external link to access that port.
And managed to run the server by running this-
!python manage.py runserver 8000
But I can only land on the The install worked successfully! Congratulations! page.
And Created a super user using this-
!python manage.py createsuperuser
But I can't access the admin page and other pages. Please Help me.Thank You
Check the file settings.py. It must contain code
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
When running python manage.py migrate not all migrations were run, specifically django_celery_results, authtoken and sessions. This resulted in the application related migrations erroring out.
However, if I first manually migrate those three, and then specifically migrate auth (not sure why I'd need to migrate that again) and then do python manage.py migrate it'll work.
The installed apps on Django are like so:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'django_celery_results',
'celery.contrib.testing.tasks',
'api_app'
]
I'm wondering why that's happening, I thought migrate will run all the migrations listed in "operations to perform".
Your api_app.0002 migration creates a user without setting last_login. Therefore this migration must be run after the auth 0005 migration that allows nulls in this column.
If you add a dependency to your migration, then Django will run them in the correct order.
class Migration(migrations.Migration):
dependencies = [('auth', '0005_alter_user_last_login_null')]
I'm currently beginning a project in Django 1.10, trying to use the included flat pages application. After installing the apps within my (base) settings file:
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',
'first_app']
SITE_ID = 1 # for use with 'django.contrib.sites'
Yet when I run python manage.py migrate, the console returns the following error:
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an
explicit app_label and isn't in an application in INSTALLED_APPS.
Can someone explain to me what is causing this error, when I clearly declared the app in my 'INSTALLED_APPS' list?
Thanks in advance for any advice!
NOTE: It may be worth noting that I'm using multiple settings files, but this code is within the base settings file (the other files change small things such as the DEBUG variable), but i've had no problems running the server or any other errors.
When I run my Django tests for an app, only the models for that app are loaded.
My app has a dependency on a second app and requires that the tables for the second app's models be present in the database.
How is this achieved?
Each time your create an app, you need to add it to the installed apps, for do that open your setting file, and add your app to installed apps:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'your_test_app',
'here_goes_your_other_app'
)
Then close the server, run python manage.py syncdb and try.