MySQL Auto-Increment Issue – Table Shows ID (Auto-Increment) as 0 in All Rows

auto-incrementMySQLphpmyadmin

I am using laravel 5.2 to develop my web application. i recently uploaded the web application from localhost to my hosting account. I also imported MySQL tables from phpmyadmin localhost to my phpmyadmin localhost in my hosting account.

When I opened my phpmyadmin I noticed that in one of my tables, the id (which is set to auto-increment) is not working. It is displaying 0 in all the rows.

When I set the id to auto-increment in phpmyadmin it gives me the following error:

#1075 – Incorrect table definition; there can be only one auto column and it must be defined as a key

Table structure in phpmyadmin

enter image description here

SHOW CREATE TABLE

enter image description here

Best Answer

The problem is that you can not create AUTO_INCREMENT without a key so try something like this:

CREATE TABLE `project_application` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`project_title` varchar(255) NOT NULL,
`project_id` int(11) NOT NULL,
`team_leader` varchar(255) NOT NULL,
`team_member` text,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE     CURRENT_TIMESTAMP,
`createt_et` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) 

Hope this helps