I’m trying to install this 4chan clone: https://github.com/Ro0ul/4Chan-Clone
I’m executing one of the queries on the sql folder on phpmyadmin:
CREATE TABLE comment(
id INT AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
body TEXT NOT NULL,
post_id INT NOT NULL,
posted_at DATETIME NOT NULL,
image_src VARCHAR(255),
board VARCHAR(50) NOT NULL,
FOREIGN KEY(post_id)
REFERENCES post(id)
ON DELETE CASCADE
)
But I get the error: #1075 – Incorrect table definition; there can be only one auto column and it must be defined as a key
How can I fix this without changing much the table (because like I said I want to install that 4chan clone)
Thanks in advance
2
Answers
You can define column
id
as PRIMARY KEYTest it here
From CREATE TABLE Statement
In simple terms AUTO_INCREMENT attribute can be used to generate a unique identity for new rows. And it is a perfect candidate for
PRIMARY KEY
.Add PRIMARY KEY after AUTO_INCREMENT
Better would be