I was trying to create migrations within an existing app using the makemigrations command but it outputs "No changes detected".
The code I used for that is
python3 manage.py makemigrations
I tried:
python3 manage.py makemigrations polls
and it shows
"App 'polls' could not be found. Is it in INSTALLED_APPS?"
Here is my INSTALLED_APPS of the 'settings.py' file
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls.apps.PollsConfig',
]
I know some people simply put 'polls', it doesn't work either
Here is my folder structure:
Here is my 'apps.py':
from django.apps import AppConfig
class PollsConfig(AppConfig):
name = 'polls'
Here is my urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('new', views.new),
]
I am using django2.1 and python3.8.
Related
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/
app/models:
from django.db import models
# Create your models here.
class Blogpost(models.Model):
topic = models.TextField(null=True)
descrip = models.TextField()
fd = models.CharField(max_length=150)
->I installed app already
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'website.apps.SbuiltConfig',
'rest_framework',
]
->I Register models already
from django.contrib import admin
from models import Blogpost, Blog, testblog
# Register your models here.
admin.site.register(Blogpost)
but it's still no change detected
enter image description here
You should mention your app/folder name in the INSTALLED_APPS list.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'website.apps.SbuiltConfig',
'rest_framework',
# If your app's root folder name is Blogpost
'Blogpost',
# Or if your app's folder name is website
'website',
]
then after saving your settings.py, in terminal/shell:
python manage.py makemigrations
python manage.py migrate
you can also mention your app's name explicitly in command:
python manage.py makemigrations Blogpost
python manage.py migrate
if your app's name is website then:
python manage.py makemigrations website
python manage.py migrate
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):
...
I'm trying to create a robots.txt file for my django website following this tutorial
The end result is good on development and everything is working. However, when I pushed the files into production I got a Server Error (500) even though I changed all the 127.0.0.1:8000 into mywebsite's domain.
My settings.py Installed apps looks like this:
INSTALLED_APPS = [
'search.apps.SearchConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
'robots',
'django.contrib.sites',
]
My main project's urls.py looks like this:
urlpatterns = [
path('admin/', admin.site.urls),
path("", include("search.urls")),
path("sitemap.xml", sitemap, {'sitemaps': sitemaps}),
path('robots.txt',include('robots.urls')),
]
I installed the django-robots using pip install, and I did the necessary migrations on my production server but it doesn't fix the problem.
I am getting the following error when importing the models module in Django.
/Users/markcollier/Documents/Adapt/Taboo/TabooAPI/env/lib/python2.7/site-packages/django/contrib/contenttypes/models.py:161: RemovedInDjango19Warning: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class ContentType(models.Model):
I have searched around and tried all of the suggested solutions to similar problems.
I think it has something to do with how my settings.py file is set up but could be wrong. All help would be much appreciated.
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'rest_framework',
'api.apps.ApiConfig',
]
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'api.permissions.IsOwner',
)
}
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
apps.py
from __future__ import unicode_literals
from django.apps import AppConfig
class ApiConfig(AppConfig):
name = 'api'
directory structure:
django_api
api
__init__.py
apps.py
migrations
models.py
permissions.py
serializers.py
signals.py
temp.py
urls.py
views.py
datasets
django_site
__init__.py
settings.py
urls.py
wsgi.py
db.sqlite3
manage.py
According to the error message you posted, the problem is not with your own app but with django.contrib.django.contenttypes.models.ContentType - and googling for this exact error message shows you're not the first having this issue.
Since contenttypes is in your installed apps, the problem comes from contenttype being imported before being "officialy" loaded. So what you need know is to find out where contenttype is imported and which of these imports happens too soon - or just first try to place it first in your settings INSTALLED_APPS as FeroxTL suggest, it might (or not) solve the problem.