【发布时间】:2019-08-22 19:54:56
【问题描述】:
创建一个自行车租赁应用程序并将 addBike() 实现到数据库。 addCustomer() 使用此代码,但我认为这是因为它没有外键。当一半表是外键时如何插入数据库?
谢谢!
newbike.js:
add() {
bikeService.addBike(
this.wheelsize,
this.frame,
this.gears,
this.typeId,
this.location,
this.orderId,
id => {
history.push('/bike/' + id);
this.props.history.push('/regbike');
}
);
}
}
services.js:
connection.query(
'insert into Bike (wheelsize, frame, gears, typeId, statusId, location, orderId) values (?, ?, ?, ?, ?, ?, ?)',
[wheelsize, frame, gears, typeId, statusId, location, orderId],
(error, results) => {
if (error) return console.error(error);
success(results.insertId);
}
);
}
export let bikeService = new BikeService();
【问题讨论】:
-
您只需确保已正确设置所有包含外键的列
标签: javascript mysql sql reactjs