因需求需要,在项目中新增了中间表,但是需要之前的数据,顾记录下过程:
原来两个表:posts和users,关联关系:posts.poster_id = user.id;
新增中间表:posts_x_users,字段:posts_id,users_id,posts_id外键对应posts.id,users_id外键对应users.id
数据迁移:经查资料,需要用的insert into select语句
SQL:
INSERT INTO posts_x_users(posts_id,users_id)
SELECT posts.id,users.id
FROM posts
INNER JOIN users ON posts.poster_id = users.id;