I have following entities: residential listings, commercial listings, lease listing and featured listings which holds featured properties for each user. The most logical seems to leverage supertype/subtype approach and create following tables:
CREATE TABLE listings (
id ...,
listPrice ...,
...
PRIMARY KEY (id)
)
CREATE TABLE residential (
id ...
...
PRIMARY KEY (id),
FOREIGN KEY id REFERENCES listings(id)
)
CREATE TABLE featuredListings (
id ..,
userId ...,
featuredListingId ...
PRIMARY KEY (id),
FOREIGN KEY featuredListingId REFERENCES listings(id)
)
But when i try to create residential table, Mysql returns error "MySQL Error Number 1005. Can't create table 'residential' (errno: 150)"
Maybe my DDL is incorrect. Or is it even possible to have PK which in the same time is FK in MySQL? If not, what is the best design for such scenario?