Django Model isn't migrating even after i saved and added app to installedApps

Issue

from django.db import models
from django.contrib.auth import get_user_model

user = get_user_model

# Create your models here.
class Post(models.Model):
    title = models.CharField(max_length=200)
    text = models.TextField(max_length=100)
    author = models.ForeignKey(
        user,
        on_delete=models.CASCADE)
    created_date = models.DateTimeField()
    published_date = models.DateTimeField()

When I run:

python manage.py migrate

Then shows:

PS C:\Users\hp\Desktop\djangomodels\I4G006918VEO> python manage.py migrate 
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  No migrations to apply.

Solution

It should be user=get_user_model() not user=get_user_model.

It returns the User model that is active in this project.

Try this:

from django.db import models
from django.contrib.auth import get_user_model

user = get_user_model()

# Create your models here.
class Post(models.Model):
    title = models.CharField(max_length=200)
    text = models.TextField(max_length=100)
    author = models.ForeignKey(
        user,
        on_delete=models.CASCADE)
    created_date = models.DateTimeField()
    published_date = models.DateTimeField()

Then, run both the commands as python manage.py makemigrations and python manage.py migrate.

Answered By – Sunderam Dubey

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published