简体   繁体   中英

Having trouble with SQLite3 table in Django

I am learning Django and have created a table in Django using PyCharm. I entered some values in the table and after that, I added another column to the table. Now, when I attempted to makekigrations, it happened successfully but when I tried to migrate, a lot of errors appeared which mainly said that an Empty Column is being attached and so on. After that I made a lot of tries, first by allowing Null values in that column then by commenting out the column but unsuccessfully. Now, even if I maintain the same code in the models.py file, the same errors keep appearing.

Here is the code of models.py file:

from django.db import models


    class Albums(models.Model):
       # name = models.CharField(max_length=250, default=None)
       artist = models.CharField(max_length=250)
       duration = models.CharField(max_length=20)

    # def __str__(self):
    #     return self.artist


class Songs(models.Model):
    album = models.ForeignKey(Albums, on_delete=models.CASCADE)
    name = models.CharField(max_length=250)

PS: I have tried restarting PyCharm as well.

You needed to put null=True, blank=True in there before making migrations. Because you didn't do that, you now have a bad migration file and every time you make new migrations, you're just adding a file to the migrations folder, but the bad migration file still exists and is unapplied. You need to go into your migrations folder and delete the bad migration file that is causing errors. Once you do that, you should be able to migrate successfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM