简体   繁体   中英

How to allow null on foreign key column in mysql php?

I have mysql table users . In the registration form country is compulsory but district is not compulsory. Both are foreign key column.

So some user keep empty the district field. Than what & how should i pass district_id from ajax, if district is blank?

I have already set null the district_id null & passing "null" value for district_id column. But error is incorrect integer value for district_id column.

Pls. suggest an idea.

如果表字段已经用“NULL”属性检查过,只是你没有向该列传递任何值

a primary key cannot be null. You can create a "special" record in district table to represent a value when there is not value setted from user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM