-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: can't create table, index and foreign key in the same transaction #24626
Copy link
Copy link
Closed
Labels
A-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)O-communityOriginated from the communityOriginated from the communitydocs-known-limitationdocs-todo
Description
This is on cockroachdb 2.0.0 on linux 64 bit.
These statements:
start transaction;
create table t_parent (id varchar primary key);
create table t_child (id varchar primary key, parent_id varchar);
create index idx_t_child_parent_id on t_child (parent_id);
alter table t_child add constraint fk_t_child_parent_id foreign key (parent_id) references t_parent (id);
commit;
Give this error:
pq: foreign key requires an existing index on columns ("parent_id")
I am not sure if this is an issue or a known limitation. I am working on a java application which uses automatic migration from the create scripts, but they fail when used in a transaction. I hope to avoid having only the foreign keys moved to their own transaction and separating the index code from its corresponding alter code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)O-communityOriginated from the communityOriginated from the communitydocs-known-limitationdocs-todo