Reputation: 81
I am currently learning how to use Django 3 (and Python 3.8) and I am following a tutorial to create a simple blog. I am getting a good grasp of the basic concepts so far but I am stuck at creating a migrations file.
When I enter the python manage.py makemigrations blog
command into Windows Powershell, I get the error message: No installed app with label 'blog'
. I have searched high and lo for an answer but I am still scratching my head. I am wondering if you lovely people would be able to offer any advice on the matter.
Here's my settings.py
file:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print("BASE_DIR = ", BASE_DIR)
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'django_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'django_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
And here's my models.py
file of the blog app:
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=100, unique=True)
email = models.EmailField(unique=True)
active = models.BooleanField(default=False)
created_on = models.DateTimeField()
last_logged_in = models.DateTimeFieldP()
class Category(models.Model):
name = model.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=100, unique=True
author = models.ForeignKey(Author, on_delete=models.CASCADE)
class Tag(model.Model):
name = models.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=100, unique=True)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
class Post(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True)
content = models.TextField()
pub_date = models.DateTimeField(auto_now_add=True)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
tags = models.ManyToManyField(Tag)
I'll also post the directory to my blog app as well:
first_project
--my_venv
--django_project
----django_project
----__init__.py
----asgi.py
----settings.py
----urls.py
----wsgi.py
----blog
----migrations
----__init__.py
----templates
----__init__.py
----admin.py
----apps.py
----models.py
----tests.py
----urls.py
----views.py
----templates
----manage.py
----db.sqlite3
EDIT: Sorry about the missing blog app files, I've added the auto-generated files to the directory.
I'll also add the apps.py
file, which is:
from django.apps import AppConfig
class BlogConfig(AppConfig):
name = 'blog'
As requested, this is the result of the command python manage.py showmigrations
:
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
[X] 0009_alter_user_last_name_max_length
[X] 0010_alter_group_name_max_length
[X] 0011_update_proxy_permissions
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial
Upvotes: 3
Views: 10102
Reputation: 81
Thank you guys for all your help. I found the solution to this problem!
It was giving me the error as explained in my original post because of anti-virus software: Comodo. Once I temporarily deactivated that software and when I corrected all the silly mistakes in my models.py
folder, the makemigrations process worked and I can carry on programming.
I just want to thank you guys again for taking the time to advise me on what to do.
P.S. I just wanted to add that this Comodo antivirus software, has caused all sorts of unexplained errors during my time learning Python and then Django, which was fixed once I temporarily deactivated the software
Upvotes: 3
Reputation: 128
Please Use this command to create app in django:
python manage.py startapp your_app_name
Or:
django-admin startapp your_app_name
Upvotes: 0
Reputation: 667
It looks like you don't have all the files like suggested in comments. At least you will need to have file apps.py under your app folder, but as you have models defined and you mentions models.py and it is not listed in your file list it seems that list is not complete.
File apps.py looks like this:
from django.apps import AppConfig
class BlogConfig(AppConfig):
name = 'blog'
Please check and post your complete file list.
Upvotes: 0
Reputation: 1610
You have not created the blog app using the django way. You should create an app in django using the following command.
python manage.py startapp blog
Upvotes: 0