2

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.

0

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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')"
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.
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.