Unable to fetch foreign key column from base table

Hi everyone,

kindly someone help me with this query.

I am trying to create a website. where as facing problem with fetching the foreign key.
Created tables in postgresql.

create table customer(customer_id serial primary key,
username varchar(30) not null,
first_name varchar(50),last_name varchar(50),
email varchar(50) not null,
create table customer1(id serial,
cid integer not null,
mobile bigint not null,
age int,
primary key(id),
constraint fk_customer
foreign key(customer_id) references customer(customer_id),
Also by running command :
python manage.py inspectdb

i get the same tables created in db in models.py

class Customer1(models.Model):
cid = models.IntegerField()
mobile = models.BigIntegerField(unique=True)
age = models.IntegerField(blank=True, null=True)

class Meta:
    managed = False
    db_table = 'customer1'

class Customer(models.Model):
uesrname = models.CharField(max_length=40, blank=True, null=True)
first_name = models.CharField(max_length=40, blank=True, null=True)
last_name = models.CharField(max_length=40, blank=True, null=True)
email = models.CharField(max_length=40, blank=True, null=True)

class Meta:
    managed = False
    db_table = 'customer2'

Now customer_id column from customer table is not falling in cid column of customer table.
Unable to build the relation between base table and another foreignkey table.

why not just use Django ORM instead of writing raw SQL like that? Django can abstract that so you don’t need to do that


I suggest you start with working your way through either the Official Django Tutorial or the Django Girls Tutorial. Either one of them are going to give you the fundamental knowledge you need to properly get started with Django.

Also - when posting blocks of code here, surround each block with lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted, which is critical with Python.