1

I am new to django and having an issue with integrating the Django auth model directly in apps' models by referring to it as:

class Question(models.Model):
    question_text = models.CharField(max_length=200, blank=False)
    pup_date = models.DateField('date_published',auto_now=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE)

But when trying to run python manage.py makemigrations it gives the following error

Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py

So would you please help me in this, I don't need to create a custom User model.

regards

Pedram Parsian
  • 3,750
  • 3
  • 19
  • 34
Ahmed Al-Haffar
  • 520
  • 4
  • 17
  • This is not such much an error but rather it is a helpful feature of Django. Your migration is saying that you are trying to add an attribute (column) to class Question. Without seeing the full output, I can't say for certain, but I'm guessing you are trying to add author (null=False) to Question when there are already questions in the database. So, you can either provide a one time value for the existing rows in Question, or you will have to update your model. You could find the PK of your own user, and enter it when asked by the migration tool. Please show the full output and we can help mor – anowlinorbit Dec 03 '19 at 13:00
  • Actually this is the full message, and there are no records in Question model, but I think as author is a ForeignKey for user Model `django.contrib.auth.models.User` and author is actually a PK for User Model. That's why it should be not nullable – Ahmed Al-Haffar Dec 03 '19 at 15:17

1 Answers1

-1
question_text = models.CharField(max_length=200, null=True, blank=True)
Amal T S
  • 3,327
  • 2
  • 24
  • 57
fischer
  • 99
  • 1
  • 8