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