迁移不适用于特定模型

拉克斯曼·古普塔

问题是,每当我尝试迁移更改时,迁移都不适用于名为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__文件夹

然后分别重新运行makemigrationsmigrate命令

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章