Lately I've been working on a Django 4.1 app, and I've got a model with following fields:
from django.db import models
from django.utils.translation import gettext_lazy as _
import datetime
class CarArticle(models.Model):
class manufacturers(models.TextChoices):
BMW = 'BMW', _('BMW')
AUDI = 'AUDI', _('AUDI')
LEXUS = 'LEX', _('LEXUS')
MERCEDES = 'BENZ', _('MERCEDES')
VOLKSWAGEN = 'VW', _('VOLKSWAGEN')
VOLVO = 'VOLVO', _('VOLVO')
FORD = 'FORD', _('FORD')
SAAB = 'SAAB', _('SAAB')
id = models.BigAutoField(primary_key=True)
articleId = models.CharField(max_length=10)
manufacturer = models.CharField(
max_length=5,
choices=manufacturers.choices
)
series = models.CharField(max_length=255)
gen = models.CharField(max_length=255)
year = models.CharField(max_length=20)
mileage = models.CharField(max_length=20)
engSize = models.CharField(max_length=255)
fuelType = models.CharField(max_length=255)
price = models.CharField(max_length=255)
createdAt = models.DateField(auto_created = True,default=datetime.date.today)
updatedAt = models.DateField(auto_now=True)
Upon changing any field and running py manage.py makemigrations
, I'm presented with No changes detected
.
My admin.py
looks like that:
from django.contrib import admin
from .models import *
admin.site.register(CarArticle)
Previously, I removed migrations files and folder since I've been remodeling the database over and over.
When I migrate with newly set database, I'm presented with these tables only:
mysql> show tables;
+----------------------------+
| Tables_in_capi_tool |
+----------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| django_admin_log |
| django_content_type |
| django_migrations |
| django_session |
+----------------------------+
10 rows in set (0.01 sec)
Could deleting migrations folder with migrations file inside it screw up the makemigrations
and migrate
commands?
ps my application is registered within INSTALLED_APPS
as well
An answer to this was much simpler than I thought - Since the issue started happening after the removal of migrations folder - I took a deeper dive into documentation of this topic. There I found that migrations folder with __init__.py
file is necessary for it to work, and therefore my issue is no more:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.