Hi i'm trying to combine Django backend and postgresql database together.

**Here is my database tables:**

[![tables](https://i.stack.imgur.com/cauIZ.png)](https://i.stack.imgur.com/cauIZ.png)

**My models.py in Django**

```
from django.db import models

# Create your models here.
class Categories(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.TextField(null=True, unique=True)

    class Meta:
        db_table = 'categories'

    def __str__(self):
        return self.name
class Website(models.Model):
    id = models.IntegerField(primary_key=True)
    site = models.TextField(null=True, unique=True)

    class Meta:
        db_table= 'website'

    def __str__(self):
        return self.site

class Discount(models.Model):
    id = models.IntegerField(primary_key=True)
    product_name = models.TextField()
    product_price = models.TextField()
    product_old_price = models.TextField()
    product_link = models.TextField()
    category_name = models.ForeignKey(Categories, on_delete=models.CASCADE, null=True, to_field='name')
    product_site = models.ForeignKey(Website, on_delete=models.CASCADE, null=True, to_field='site')
    product_image = models.TextField()
    class Meta:
        db_table = 'discount'

    def __str__(self):
            return self.product_name

```

I managed to link Django and postgresql together following tutorials but when i try to migrate the database for the first time it come with this error :

> 
> column discount.category\_name\_id does not exist LINE 1:
>  ..."."product\_old\_price", "discount"."product\_link", "discount"...
>  ^ HINT: Perhaps you meant to reference the column "discount.category\_name".
> 
> 
> 

i though i linked my foreign key from discount.category\_name to categories.name with to\_field='name' in the ForeignKeyField but somehow it used the discount.category\_name\_id ? i don't know where the category\_name\_id is, it's not in my tables

Any help would be appreciate!