I'm following this tutorial: https://www.youtube.com/watch?v=T9X5e_yjQB8&list=PLAkMqlQoeMeiwvNWpe3mhgQxAa1jiGwmt&index=22.
I created a "pages" table, and a "users" table for a website. When I try to insert more than 1 user in users table, PHPMyAdmin throws this error: 1062 duplicate entry '0' for key 'primary'.
I tried to get the constraint as per MySQL 1062 - Duplicate entry '0' for key 'PRIMARY' but it doesn't show it.
I've been reading on foreign keys and constraints, but I don't understand why I get this error but the tutorial doesn't. How can I fix this issue?
This is the code for tables I've done:
Database: `healthcms`
--
-- --------------------------------------------------------
--
-- Table structure for table `pages`
--
CREATE TABLE `pages` (
`id` mediumint(9) NOT NULL,
`user` mediumint(9) NOT NULL,
`label` varchar(100) NOT NULL,
`title` varchar(200) NOT NULL,
`header` varchar(300) NOT NULL,
`body` longtext NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `pages`
--
INSERT INTO `pages` (`id`, `user`, `label`, `title`, `header`, `body`) VALUES
(1, 0, 'Home', 'Home Page', 'Welcome to Health!', '\"Lorem ipsum.\"'),
(2, 0, 'About', 'About us', 'About Health', ;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `pages`
--
ALTER TABLE `pages`
ADD PRIMARY KEY (`id`),
ADD KEY `user` (`user`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `pages`
--
ALTER TABLE `pages`
MODIFY `id` mediumint(9) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
------------------------------------------------------------------------
Database: `healthcms`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`id` mediumint(9) NOT NULL,
`first` varchar(200) NOT NULL,
`last` varchar(200) NOT NULL,
`email` varchar(300) NOT NULL,
`password` varchar(200) NOT NULL,
`status` int(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`id`, `first`, `last`, `email`, `password`, `status`) VALUES
(0, 'John', 'Rainey', 'john@john.com', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 1);
--
-- Indexes for dumped tables
--
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Thanks!