Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MySQL] Foreign Key fields of bigint unsigned cause "incompatible types: numeric and bigint" #1391

Open
ssherwood opened this issue Mar 28, 2024 · 0 comments
Labels
triage Needs to be triaged

Comments

@ssherwood
Copy link

I have a foreign constraint defined between two tables in MySQL:

create table foo(
  id bigint(20) unsigned not null auto_increment comment 'foo\n id\n for \n foo',
  created_on datetime default null,
  primary key(id)
);

create table bar(
  id bigint(20) unsigned not null auto_increment comment 'bar id',
  foo_id bigint(20) unsigned default null,
  primary key(id),
  constraint foo_id_fk foreign key(foo_id) references foo(id)
);

The resulting schema is:

CREATE TABLE bar (
	id bigserial,
	foo_id numeric(20),
	PRIMARY KEY (id)
) ;
ALTER SEQUENCE bar_id_seq RESTART WITH 1;
COMMENT ON COLUMN bar.id IS E'bar id';


CREATE TABLE foo (
	id bigserial,
	created_on timestamp without time zone,
	PRIMARY KEY (id)
) ;
ALTER SEQUENCE foo_id_seq RESTART WITH 1;
COMMENT ON COLUMN foo.id IS E'foo
 id
 for 
 foo';

After converting and applying the schema to YugabyteDB, I tried to manually add the constraint and get an error:

test2=# alter table bar add constraint foo_id_fk foreign key(foo_id) references foo(id);
ERROR:  foreign key constraint "foo_id_fk" cannot be implemented
DETAIL:  Key columns "foo_id" and "id" are of incompatible types: numeric and bigint.

The issue is that the foo_id bigint(20) unsigned is being converted to numeric(20) while the PK of foo (also a bigint(20) unsigned) is being converted to bigserial. As there is no equivalent for bigserial for unsigned types this will create a logical impossibility in migrating bigint(20) unsigned PKs as they technically could overflow bigserial.

@github-actions github-actions bot added the triage Needs to be triaged label Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant