In Django 2.1.7 I create a model for sub postgresql. I need the fields (question_id, option_id) of the 'options_selection' table together to be unique. When I do a migration it displays an error that the fields are not defined (Name 'question_id' is not defined). Please tell me how you can solve this problem. Here is the code I wrote

class qusetions(models.Model): question_name = models.CharField(max_length = 60) question_type = models.CharField(max_length = 25) class Meta: db_table = 'qusetions' class options_selection(models.Model): question_id = models.ForeignKey(qusetions, on_delete=models.CASCADE) option_id = models.IntegerField() option_name = models.TextField() class Meta: db_table = 'options_selection' unique_together = ((question_id, option_id),) 

    1 answer 1

    The answer was unpredictable, in unique_together the field names should be enclosed in quotes))

     unique_together = (('question_id', 'option_id'),)