问题是,每当我尝试迁移更改时,迁移都不适用于名为Userinfo的特定应用。我终端中的信息是
Operations to perform:
Apply all migrations: admin, auth, books_details, contenttypes, sessions
Running migrations:
No migrations to apply.
而且该应用未列在我的上面列表中,我也不知道这可能是什么原因
该应用的Models.py
from django.db import models
import os
# from django.conf import settings
def upload_rename(instance,filename):
exe=filename.split('.')[-1]
filename=instance.user_name+'.'+exe
try:
os.remove(os.path.join('images','profile_image',instance.user_name,filename))
except:
pass
return os.path.join('profile_image',instance.user_name,filename)
class Userinfo(models.Model):
''' User info '''
user_name = models.CharField(max_length=30, unique=True, null=False,primary_key=True)
full_name = models.CharField(max_length=50, null=False)
user_email = models.EmailField(max_length=254)
college_name = models.CharField(max_length=50)
city = models.CharField(max_length=50)
country = models.CharField(max_length=50)
profile_img = models.ImageField(upload_to=upload_rename, blank=True)
''' The Change I added '''
varified_user =models.BooleanField(default=False)
该应用程序的Admin.py
from django.contrib import admin
from .models import Userinfo
admin.site.register(Userinfo)
在setting.py中的INSTALLED_APP
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'userinfo',
'rest_framework',
'phonenumber_field',
'books_details',
]
移居
from django.db import migrations, models
import userinfo.models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Userinfo',
fields=[
('user_name', models.CharField(max_length=30, primary_key=True, serialize=False, unique=True)),
('full_name', models.CharField(max_length=50)),
('user_email', models.EmailField(max_length=254)),
('college_name', models.CharField(max_length=50)),
('city', models.CharField(max_length=50)),
('country', models.CharField(max_length=50)),
('profile_img', models.ImageField(blank=True, upload_to=userinfo.models.upload_rename)),
('varified_user', models.BooleanField(default=False)),
],
),
]
这是我认为您应该看到的一些图像,我不知道为什么它说创建模型userinfo,因为它已经存在数据库屏幕截图,请提供任何帮助吗???
我想你需要先运行makemigrations
命令:
python manage.py makemigrations userinfo
然后运行migrate
命令:
python manage.py migrate
请参阅django docx的此tuto:https://docs.djangoproject.com/en/3.1/intro/tutorial02/#activating-models了解更多说明
通过运行makemigrations,您将告诉Django您对模型进行了一些更改(在这种情况下,您进行了新的更改),并且希望将更改存储为迁移。
在某些情况下,最好是从零开始重新启动迁移过程,以解锁这种情况,因此,由于您处于开发模式,因此我建议您删除:
migrations
每个应用程序文件夹下的文件__pycache__
文件夹然后分别重新运行makemigrations
和migrate
命令
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句