I created a new database and added some foreign keys, cause I didn't this in my database before that and my whole webpage got's many issues.. thats why I decided to create a new one, with all the foreign keys I need.
Now I created a new user on my webpage and it works.. But If I'm trying to create a thread with this user, I'm getting this error message:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (Laravel.threads, CONSTRAINT threads_ibfk_2 FOREIGN KEY (themen_id) REFERENCES themes (id)) (SQL: insert into threads (themen_id, thread, content, user_id, updated_at, created_at) values ({id}, unicorn, rainbows, 1, 2016-03-23 14:11:23, 2016-03-23 14:11:23))
and below this error, nearly the same error again:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (Laravel.threads, CONSTRAINT threads_ibfk_2 FOREIGN KEY (themen_id) REFERENCES themes (id))
well, I don't haven't a single idea, what this means. I hope someone of you can help me there.
Thats how I created the table:
CREATE TABLE threads
(
id int AUTO_INCREMENT PRIMARY KEY,
user_id int NOT NULL,
themen_id int NOT NULL,
thread varchar (120),
content varchar (1200),
created_at timestamp,
updated_at timestamp,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (themen_id) REFERENCES themes(id)
);
CREATE TABLE comments
(
id int AUTO_INCREMENT PRIMARY KEY,
thread_id int NOT NULL,
user_id int NOT NULL,
comment text,
created_at timestamp,
updated_at timestamp,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (thread_id) REFERENCES threads(id)
);
CREATE TABLE themes
(
id int AUTO_INCREMENT PRIMARY KEY,
thema text,
created_at timestamp,
updated_at timestamp
);
CREATE TABLE users
(
id int(10) PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255),
email VARCHAR(255),
password VARCHAR(60),
remember_token VARCHAR(100),
created_at timestamp,
updated_at timestamp
);
I'm working with Laravel, of course I've changed the database name in the .env file. Well, I don't really now what to do right now.
Any help?
Thanks!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire