X
X
xxx2017-02-18 16:24:35
Django
xxx, 2017-02-18 16:24:35

Django migration?

I decided to add a new app to the project. Created a model:

class Comments_appl(models.Model):
  user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)
  content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
  object_id = models.PositiveIntegerField()
  content_object = GenericForeignKey('content_type', 'object_id')
  content = models.TextField()
  datetime = models.DateTimeField(auto_now_add = True)


  def __unicode__(self):
    return str(self.user.username)
  def __str__(self):
    return str(self.user.username)

After makemigrations I get:
You are trying to add a non-nullable field 'content_type' to comments_appl without a default; we can't do that (the database needs something to populate existing rows).
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
Select an option:

From the message it is clear that it is impossible to leave the content-type type without the default attribute . But what if I don't need it and want to leave it like that?
Tried deleting the migration and overwriting, still get this error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2017-02-18
@sim3x

Learn the man for proper naming of models in django and classes in python
Do not use generic FK until you understand the basic concepts of the framework

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question