0

So i have a user that can post comments on effects, im linking up my models and i keep getting the non-nullable error no matter what ive tried. Everyone says it needs to have null=True. It isn't working lol. What am I not seeing here?

This is the official error:

django.db.utils.IntegrityError: NOT NULL constraint failed: effect_modules_comment__new.author_id

And my models:

class Effect_module(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=255)
    description = models.TextField()
    html = models.TextField(default='')
    css = models.TextField(default='')
    js = models.TextField(default='')
    up_votes = models.IntegerField()
    down_votes = models.IntegerField()
    effect_author = models.ManyToManyField('UserProfile')

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    effects = models.ManyToManyField(Effect_module)

class Comment(models.Model):
    comment_author = models.ForeignKey(User, null=True)
    comment = models.TextField(default='No Comment Here')
    effect_object = models.ForeignKey(Effect_module)
4
  • Try including blank=True. Commented Aug 16, 2015 at 18:23
  • i added blank=True and during makemigrations, it asked me to provide the default what should i add to that? it wouldn't allow me to enter null=True or anything so i just used that suggested timezone.now() lol and now its still saying nullable error on migrate Commented Aug 16, 2015 at 18:34
  • Did you add the foreignkey after the Comment model itself? Do you already have comments in the db? Commented Aug 16, 2015 at 19:31
  • yeah i did...i had a feeling i just messed something up with the migrations and stuff so i just cleared the DB..it was just dummy data anyway Commented Aug 16, 2015 at 19:33

1 Answer 1

3

Delete all migration scripts. Add null=True means it can be NULL in the database, blank=True means that it can be left blank in forms.

Then

python manage.py makemigrations
python manage.py migrate
Sign up to request clarification or add additional context in comments.

Comments

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.