0

I am really stuck here. I went back and edited some models that I made a while ago and now I can't get anything to migrate without getting:

django.db.utils.IntegrityError: NOT NULL constraint failed: new__accounts_instrument.room_id

The model that seems to be causing problems:

acounts/models.py

class Instrument(models.Model):
    LEVEL = (
    ('HS', 'HS'),
    ('MS', 'MS'),
    )
    event = models.ForeignKey(Event, blank=False, null=True, on_delete=models.PROTECT)
    name = models.CharField(max_length=200, blank=False, null=True)
    abbreviation = models.CharField(max_length=10, blank=False, null=True)
    level = models.CharField(max_length=200, blank=False, null=True, choices=LEVEL)
    room = models.ForeignKey(AuditionRoom, default=None, on_delete=models.PROTECT)

I've tried deleting the migration history but that throws other codes so I "undo" it. I've tried dropping the instrument table but that didn't seem to matter.

I'm very grateful for any pointers as I am pretty frustrated at the moment. Please let me know if you need more code snippets, Thanks.

Javad
  • 2,033
  • 3
  • 13
  • 23
Matt Schucker
  • 37
  • 1
  • 6

1 Answers1

3

This error usually means that a field that is required was not provided, another try can be setting the null=True, blank=True attributes in your room field field.

Also you can go to the migrations folder and delete manually files that have 000*_blah-blah type of name, you can delete, probably all, but 0001_initial.py file. After that run ./manage.py makemigrations app_you_are_updateing, it should update your database.

Javad
  • 2,033
  • 3
  • 13
  • 23
  • Thanks, @Javad. If I add "null=True, blank=True" , delete all migrations other than 0001_initial.py, and run "manage.py makemigrations accounts" I get a huge long error that ends with "django.db.migrations.exceptions.NodeNotFoundError: Migration students.0002_student_school dependencies reference nonexistent parent node ('accounts', '0012_alter_auditionroom_event')" – Matt Schucker Jul 11 '22 at 22:13
  • If you're in development and your migrations is not very important, for other applications removed all migrations and make migrations from first for all your applications. – Javad Jul 12 '22 at 08:38
  • Sorry I misunderstood that you wanted me to delete my database. I decided to do that on my own about an hour ago actually. I had been wanted to add and AbstractUser model so it was a good time to do it. Things seem to be working now. thanks for your time! – Matt Schucker Jul 12 '22 at 15:13