Новые миграции проектов django не отражаются в базе данных
Я пытаюсь создать новый проект django. Я использую Adminer для GUI моей базы данных и docker для моих контейнеров.
Я добавил модель, Notification.py
и создал миграции для ее установки на базу данных. Я могу выполнить эту миграцию в контейнере Docker без ошибок.
Однако в Adminer я не вижу таблицу Notification, которую я создаю. Я также включаю сюда мою установку docker, на всякий случай, если причина в этом.
Я также попытался запустить SQL непосредственно в Adminer:
root@65787223f662:/mos-nss# python manage.py sqlmigrate main 0001
BEGIN;
--
-- Create model Notification
--
CREATE TABLE "main_notification" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "sender_id" integer NOT NULL, "receiver_id" integer NOT NULL, "notification_group_id" integer NOT NULL, "notification_type" varchar(255) NOT NULL, "date_created" datetime NOT NULL, "is_deleted" bool NOT NULL);
COMMIT;
... что приводит к ошибке, когда я копирую и вставляю автоматически созданный запрос и запускаю его:
Error in query (7): ERROR: syntax error at or near "AUTOINCREMENT"
LINE 1: ..._notification" ("id" integer NOT NULL PRIMARY KEY AUTOINCREM...
Трассировка из моего терминала во время выполнения миграций:
root@65787223f662:/mos-nss# ./manage.py makemigrations main
Migrations for 'main':
main/migrations/0001_initial.py
- Create model Notification
root@65787223f662:/mos-nss# python manage.py migrate main
Operations to perform:
Apply all migrations: main
Running migrations:
No migrations to apply.
root@65787223f662:/mos-nss# python manage.py migrate main zero
Operations to perform:
Unapply all migrations: main
Running migrations:
Rendering model states... DONE
Unapplying main.0001_initial... OK
root@65787223f662:/mos-nss# python manage.py migrate main
Operations to perform:
Apply all migrations: main
Running migrations:
Applying main.0001_initial... OK
root@65787223f662:/mos-nss#
0001_initial.py
# Generated by Django 4.0.4 on 2022-06-01 18:44
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Notification',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sender_id', models.IntegerField(help_text='ID of the user who sent the notification', verbose_name='Sender ID')),
('receiver_id', models.IntegerField(help_text='ID of the user who received the notification', verbose_name='Receiver ID')),
('notification_group_id', models.IntegerField(help_text='ID of the group that the notification is about', verbose_name='Notification Group ID')),
('notification_type', models.CharField(help_text='Type of notification', max_length=255, verbose_name='Notification Type')),
('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date Created')),
('is_deleted', models.BooleanField(default=False, verbose_name='Deleted')),
],
options={
'verbose_name': 'Notification',
'verbose_name_plural': 'Notifications',
},
),
]
docker-compose.local.yml
version: "3"
services:
mos_nss_test_db:
image: postgres:13.0
expose:
- 5880
ports:
- 5880:5432
# persistent db
volumes:
- test-db-data:/var/lib/postgresql/data
env_file:
- .env
networks:
- test_mos_db_nw
# db GUI
mos_nss_test_adminer:
image: adminer
restart: always
ports:
- 5080:8080
networks:
- test_mos_db_nw
# web application
mos_nss_test_webapp:
build: .
image: mos_nss_test_webapp:v0.1.0
volumes:
- .:/mos-nss
env_file:
- .env
ports:
- 2448:8000
depends_on:
- mos_nss_test_db
networks:
test_mos_db_nw:
test_mos_web_nw:
mos_dev_nw:
aliases:
- nss-web # Use hyphen since underscore is not valid in domain name
networks:
test_mos_db_nw:
driver: bridge
test_mos_web_nw:
driver: bridge
mos_dev_nw:
driver: bridge
name: mos_dev_nw
volumes:
test-db-data:
Notification.py
from django.db import models
from django.utils.translation import gettext_lazy as _
# from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
User=get_user_model()
class Notification(models.Model):
id = models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID'
)
sender_id = models.IntegerField(
help_text=_("ID of the user who sent the notification"),
verbose_name=_('Sender ID'),
)
receiver_id = models.IntegerField(
help_text=_("ID of the user who received the notification"),
verbose_name=_('Receiver ID'),
)
notification_group_id = models.IntegerField(
help_text=_("ID of the group that the notification is about"),
verbose_name=_('Notification Group ID'),
)
notification_type = models.CharField(
help_text=_("Type of notification"),
verbose_name=_('Notification Type'),
max_length=255
)
date_modified = models.DateTimeField(
verbose_name='Date Modified',
auto_now=True,
),
date_created = models.DateTimeField(
verbose_name='Date Created',
auto_now_add=True,
)
is_deleted = models.BooleanField(
verbose_name='Deleted',
default=False
)
def __str__(self):
return self.notification_type
class Meta:
verbose_name = 'Notification'
verbose_name_plural = 'Notifications'