Laxman Gupta
Laxman Gupta

Reputation: 69

Migrations are not applying to specific model

The problem is whenever I try to migrate changes, migrations does'nt applying to this specific app which is named as Userinfo. The messege in my terminal is

Operations to perform:
  Apply all migrations: admin, auth, books_details, contenttypes, sessions
Running migrations:
  No migrations to apply.

And that app is not listed in my above list also i don't know what could be the reason

Models.py of that app

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 of that app

from django.contrib import admin
from .models import Userinfo
admin.site.register(Userinfo)

INSTALLED_APP in setting.py

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',
]

Migrations

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)),
            ],
        ),
    ]

Here are some images i think you should see Terminal Message when i try to migrate
I don't know why it says create model userinfo as it was pre-existing
Database screenshot Screenshot of my database where i want to apply changes please any can help with this???

Upvotes: 0

Views: 87

Answers (1)

cizario
cizario

Reputation: 4269

i guess you need first to run makemigrations command:

python manage.py makemigrations userinfo

and then run migrate command:

python manage.py migrate

refer to this tuto from django docx :https://docs.djangoproject.com/en/3.1/intro/tutorial02/#activating-models for more explanations

By running makemigrations, you’re telling Django that you’ve made some changes to your models (in this case, you’ve made new ones) and that you’d like the changes to be stored as a migration.

Update

in some cases, it's better to restart the migration process from scratch just to unlock such situation so, since you're in development mode i would suggest you deleting:

  • the database (or better make a backup)
  • migrations files under migrations folder for each app
  • and don't forget __pycache__ folders

and then rerun makemigrations and migrate commands respectively

Upvotes: 1

Related Questions