Django showing issues after second migration

for first migrations and then migrate my models.py file was :

from django.db import models

# Create your models here.
class Musician(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    instrument = models.CharField(max_length=100)
    
    def __str__(self):
        return self.first_name+" "+self.last_name

class Album(models.Model):
    artist = models.ForeignKey(Musician, on_delete=models.CASCADE)
    name = models.CharField(max_length=100)
    release_date = models.DateField()
    num_stars = models.IntegerField()

    def __str__(self):
        return self.name

for the second migration and migrate i intorduced a extra model,so the file was:

from django.db import models

# Create your models here.
class Musician(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    instrument = models.CharField(max_length=100)
    
    def __str__(self):
        return self.first_name+" "+self.last_name

class Album(models.Model):
    artist = models.ForeignKey(Musician, on_delete=models.CASCADE)
    name = models.CharField(max_length=100)
    release_date = models.DateField()
    num_stars = models.IntegerField()

    def __str__(self):
        return self.name

class Runner(models.Model):
    MedalType = models.TextChoices('MedalType', 'GOLD SILVER BRONZE')
    name = models.CharField(max_length=60)
    medal = models.CharField(blank=True, choices=MedalType.choices, max_length=10)

Now when I import these models in python shell ,the models named Musician and Album ,which were created in first migration are successfully imported.

But for model named Runner which is created in second migration shows following error while importing:

In [33]: from mooodelexp.models import Runner
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-33-2b52f6e61836> in <module>
----> 1 from mooodelexp.models import Runner

ImportError: cannot import name 'Runner' from 'mooodelexp.models' (C:\Users\DEBRAJ\Desktop\django_models_deepdive\djangooo_deepdivee\mooodelexp\models.py)

It will be really great if someones guides me in this? :slightly_smiling_face:

yeah, I figured it out. It was because I didn’t restart my shell. :blush: :sweat_smile:

2 Likes