注意:该书的ID是其标题
insert ignore into category_book
select 1 as user_id, 'name' as category_name, b.id as book_id
from book b
where b.id regexp('word') AND b.id IS NOT NULL
我明白了:
MySQL错误1452:无法添加或更新子行:外键约束失败(
book
。category_book
,CONSTRAINTfk_category_book_book1
FOREIGN KEY(book_id
)REFERENCES { {1}}(book
)ON DELETE CASCADE ON UPDATE CASCADE)
答案 0 :(得分:0)
看起来您正在尝试将记录插入到category_book中,其book_id在表格书中不存在。可能是order_book列的顺序与您在select中提供的列不同。尝试相同的查询,但指出insert子句中的列。