I created this table in Planetscale
CREATE TABLE `community` (
`id` serial PRIMARY KEY,
`name` varchar(256),
`email` varchar(256) NOT NULL,
`created_at` timestamp(2) NOT NULL DEFAULT (now()),
`last_updated_at` timestamp(2)
);
But if I try to create the this unique index
CREATE UNIQUE INDEX email_unique_index ON community (`email`);
I get this error:
18:01:21 CREATE UNIQUE INDEX email_unique_index ON community (`email`) Error Code: 1067. target: gili.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'created_at' (errno 1067) (sqlstate 42000) (CallerID: ewuobpfp487ve5g2p79l): Sql: "alter table community add UNIQUE INDEX email_unique_index (email)", BindVars: {REDACTED} 0.418 sec
I could create the same table and index in my local mysql instance.
I was able to create the index in planetscale after i removed DEFAULT (now())
as show below.
CREATE TABLE `community` (
`id` serial PRIMARY KEY,
`name` varchar(256),
`email` varchar(256) NOT NULL,
`created_at` timestamp(2) NOT NULL,
`last_updated_at` timestamp(2)
);
CREATE UNIQUE INDEX email_unique_index ON community (`email`);
Why does this happen in Planetscale? Is there a fix for it?
created_at
column you can change it to:`created_at` timestamp NOT NULL DEFAULT now()
and the indexemail_unique_index
should be created without problem. Otherwise you can directly ask the PlanetScale :: Discussions.