I have asked this question on SO but believe this is the right forum to ask, so here it is

Let say, I have a pre-defined table called cities, with almost all the cities in my country.

When a user register himself (user table), the column cities_id in the table user stores the city id from the table cities (Foreign Key, reference table cities), something like

CREATE TABLE `cities` (
`id` int,
`city_name` varchar(100)

`id` int,
`name` varchar(60)
`cities_id` FK

The user table stores the city id.

But what if I missed a few cities ... How does the user then save his city name in the user table which does not accept any city name but only IDs?

The closest I can think of is facebook. When you fill the city column it suggest you cities name and if it does not exist you get to write your own. I believe FB stores the city ID cz when you click the city hyperlink in a profile it shows a page related to that city (like, upcoming events, interesting places to visit etc).

  • First, make sure that it is in cities. Or respond to the FK complaint. – Rick James Jan 3 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.