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.
example:
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,
unique(username,email)
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),
unique(mobile)
);
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.