'Change Varchar data type to primary key
Hello i am curently trying to set up a data base in MYSQL and i want to have my Varchar element as the Primary Key but it always gives me an error like this:
Invalid use of NULL value
the command i am using is:
ALTER TABLE temp_keys ADD PRIMARY KEY (temp_key);
and here is how the table is set up:
I hope that some one of you can help me with this.
Solution 1:[1]
VARCHAR data type is not a problem. PRIMARY KEY columns must be defined as NOT NULL. Append CHANGE temp_key temp_key VARCHAR (50) NOT NULL in your query and change value(50) according to your need.
Just execute ALTER TABLE temp_keys CHANGE temp_key temp_key VARCHAR (50) NOT NULL, ADD PRIMARY KEY (temp_key);

Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Md. Al Amin Bhuiyan |
