Django Makemigrations No changed detected - python

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

Related

Error: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS

new to django
django version : Django==2.2
getting below error :
Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
while running below commands:
python3.7 manage.py collectstatic
python3.7 manage.py shell
python3.7 manage.py runserver
below is what my INSTALLED_APPS look like
INSTALLED_APPS = (
'actions.apps.MyAppConfig',
'common.apps.MyAppConfig',
'hotels.apps.MyAppConfig',
'extranet.apps.MyAppConfig',
'communication.apps.MyAppConfig',
'bulk_uploader.apps.MyAppConfig',
'registration.apps.MyAppConfig',
'channel_manager.apps.MyAppConfig',
'reports.apps.MyAppConfig',
'mobile.apps.MyAppConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'admin_shortcuts',
'guardian',
'actstream',
'rest_framework',
'django_filters',
'rest_framework.authtoken',
'oauth2app',
'ckeditor',
'stats',
'django_celery_beat',
)
any suggestion?

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/

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):
...

Django - makemigrations - No changes detected/Apps could not be found

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.

makemigrations - App 'stock_market' could not be found. is it in INSTALLED_APPS?

Edit the project/settings.py file again, and change the INSTALLED_APPS setting to include the string 'polls'. So it’ll look like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'stock_market'
]
When I run command
python manage.py makemigrations stock_market/
it gives me that error
Remove / at the end of stock_market/
python manage.py makemigrations stock_market

Categories