我正在尝试使用docker-compose为MariaDB创建一个初始化脚本。
只创建前3个表,因此不创建player_team_relation和player表。
create table if not exists user
(
user_id varchar(255) primary key,
username varchar(30) not null,
password_hash varchar(255) not null
);
create table if not exists history
(
history_id bigint auto_increment primary key,
user_id varchar(255) not null,
game_date timestamp not null,
constraint user_history_constraint foreign key (user_id) references user (user_id)
);
create table if not exists team
(
team_id bigint auto_increment primary key,
history_id bigint not null,
player_name varchar(30) not null,
score bigint not null,
hasWon bool not null,
constraint history_team_constraint foreign key (history_id) references history (history_id)
);
create table if not exists player_team_relation
(
player_id bigint not null primary key,
team_id bigint not null primary key,
constraint player_ptr_constraint foreign key (player_id) references player (player_id),
constraint team_ptr_constraint foreign key (team_id) references team (team_id)
);
create table if not exists player
(
player_id bigint auto_increment primary key,
user_id varchar(255) not null,
player_name varchar(30) not null,
wins int not null,
losses int not null,
score bigint not null,
constraint user_player_constraint foreign key (user_id) references user (user_id)
);
我已多次尝试通过删除卷并创建新容器来创建数据库。
1条答案
按热度按时间4c8rllxm1#
另一个始终建议进行错误检查的示例:
该声明
将失败,因为不可能为每个表定义多个主键。有关主键的详细信息,请查看文档。
关于列定义:您确定要使用
BIGINT
(带负数号的整数)来代替BIGINT UNSIGNED
来执行auto_increment吗?您真的需要BIGINT吗?INTEGER UNSIGNED
是4294967295 -超过世界人口的一半。