Jump to content

Changing a NOT NULL table to NULL


eMonk

Recommended Posts

I tried the following alter query but phpmyadmin still shows "No" under the Null column.

 

ALTER table model_in_city Modify city_id int unsigned null;

 

Also tried changing it in phpmyadmin and picked "null" from the dropdown menu but it's still displaying as not null. Any ideas?

 

Link to comment
Share on other sites

How can I remove the primary key for city_id?

 

I tried to remove it in phpmyadmin but got this error:

 

Error

SQL query:

 

ALTER TABLE  `model_in_city` DROP PRIMARY KEY ,

ADD PRIMARY KEY (  `model_id` )

 

MySQL said:

 

#1062 - Duplicate entry '17' for key 1

Link to comment
Share on other sites

model_id is the only unique column in the table. I had to use multiple inserts with the same model_id. So it's no longer unique? Should I remove the primary key from this as well and have no primary keys in this table?

Link to comment
Share on other sites

if the table can have more than one row with the same model_id, then model_id can not be the primary key by itself. The primary key, whether it be one column or more, has to be able to be used to uniquely identify any one row in the table.

Link to comment
Share on other sites

Also, what happens when you use primary keys incorrectly like I just did.

 

This table appears to be working without any known problems. I've been inserting, selecting, deleting, etc from this table fine...

Link to comment
Share on other sites

Technically you do not need to have a primary key, but not having one in most cases is a bad idea.  When you define a PK, you are also creating a unique index for the pk, that will be used in queries and joins.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.