pretty new to Django, i'm encountering an issue with a new model (and a new app 'blog' i made). The table blog_post didn't exist after configuring the model and makemigration.
Here is the all process i did. I'm following official tutorial:
Here is my blog/models.py:
from django.db import models
class Post(models.Model):
title = models.CharField(max_length=80)
text = models.TextField()
author = models.ForeignKey('auth.User', on_delete= models.CASCADE)
created_date = models.DateTimeField()
pub_date = models.DateTimeField()
def publish():
self.pub_date = timezone.now()
self.save()
mysite/settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog.apps.BlogConfig',
]
After the first
python manage.py makemigrations blog
Migrations for 'blog':
blog\migrations\0001_initial.py
- Create model Post
python manage.py sqlmigrate blog 0001
BEGIN;
--
-- Create model Post
--
CREATE TABLE "blog_post" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "title" varchar(80) NOT NULL, "text" text NOT NULL, "created_date" datetime NOT NULL, "pub_date" datetime NOT NULL, "author_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE INDEX "blog_post_author_id_dd7a8485" ON "blog_post" ("author_id");
COMMIT;
python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, blog, contenttypes, sessions
Running migrations:
No migrations to apply.
So, here it is. The new table didn't seem to be created. I check with a SqLite utility and the is no such table: blog_post I also check with django shell.
I double (triple) check the process:
- Change your models (in models.py).
- Run python manage.py makemigrations to create migrations for those changes
- Run python manage.py migrate to apply those changes to the database
But i'm stuck at this point. Can someone tell me what i missed ? Thank you !
Here is my database settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
python manage.py showmigrations
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
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
blog
[X] 0001_initial
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial
I check if table exist with DB Browser for SQLite, but blog_post don't exist.
Link to the github repo: https://github.com/mothinx/juliengracia
python manage.py makemigrationswithout thebloginside the command?python manage.py migrate blogshould do it.manage.py showmigrations?