Reputation: 69
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
I don't know why it says create model userinfo as it was pre-existing
Database screenshot
please any can help with this???
Upvotes: 0
Views: 87
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.
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:
migrations
folder for each app__pycache__
foldersand then rerun makemigrations
and migrate
commands respectively
Upvotes: 1