[Django]-Django model.foreignKey and return self.text errors

7👍

The problem was ForeignKey in Django 1.9 required 1 positional argument in Django 2.0 ForeignKey 2 required positional argument

  topic = models.ForeignKey("Topic", on_delete=models.PROTECT)

0👍

The reason of second issue is you missed the command after the command python manage.py makemigrations [appname], the missing command is python manage.py migrate.

0👍

To prevent this, we should use on_delete=models.PROTECT.

By default Django uses on_delete=models.CASCADE but this is not secure if object deleted accidentally.

In that case there would be no notification of deleted objects so it would be ideal to use models.PROTECT.

Leave a comment