Django 1.10: Flatpage site migration runtime error - python

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.

Related

how to solve this problem in virtual environment?

i want to activate my models in my files, my code in terminal:
(env) PS C:\Users\MadYar\Desktop\code.py\learning_log> python manage.py makemigrations learning_logs
error:
No changes detected in app 'learning_logs'
im using django to make a web application and i add models in my settings.py like that:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'learning_logs'
]
i dont know why it sais no changes detected in app 'learning_logs'
add empty __init__.py in learning_logs folder.
check if you have any models.py in learning_logs folder.
add some models, which inherited from django.models.Model:
from django import models
class MyModel(models.Model):
myfield = models.Charfield(max_length=255)
call python manage.py makemigrations learning_logs
if you see No changes detected in app 'learning_logs' again, try to read the tutorial, especially this part: https://docs.djangoproject.com/en/4.0/intro/tutorial02/

The model TokenProxy is already registered in app 'authtoken'

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

No changes detected in app 'learning_logs'

I ran the code settings.py and went to INSTALLED APPS and added learning_logs:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'learning_logs',
Then in the terminal I ran 'python manage.py makemigrations learning_logs'
However it results in 'No changes detected in app 'learning_logs'
Note that I read some other articles and got no good answer
Also note that the end bracket is supposed to be in the dictionary
You can try this:
Add __init__.py file into the app folder.
Make sure you have some models classes created in models.py file in the app
Please check your model definition and make sure that it inherits from django models.Model!
from django.db import models
class MyCustomModel(models.Model):
...

how to setup sites framework in django

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

Test Django app using models from a second app

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.

Categories