Open rnrnstar2 opened 3 weeks ago
When creating data in a connected mysql table, you need to specify an id.
await dataClient.models.Post.create({
id: 0,
name: "test",
});
I have it set as id INT AUTO_INCREMENT PRIMARY KEY
so it should be set automatically.
Also, when deploying, an error occurs in the id part of the sql file. This seems to be related to the part where the enum is set.
./amplify/data/schema.sql.ts:117:9
Type error: Type '"id"' is not assignable to type '"platform" | "gender" | "prefecture" | "ageGroup"'.
Hey👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂
Hi @rnrnstar2 , can you confirm that the schema was generated with the enum as required that way or did you manually edit it?
Also, what is the type for that field in your sql database's schema?
I am using aurora mysql on aws to create a sql database.
gender: a.enum([
"SECRET",
"MEN",
"WOMEN"
]).required(),
Since an error occurs when "required" is included, I changed the table to one that has been deleted. If possible, I would like to add a NOT NULL constraint to the enum as well.
CREATE TABLE Post (
id CHAR(36) PRIMARY KEY NOT NULL,
name VARCHAR(255) NOT NULL,
categoryId VARCHAR(255) NOT NULL,
message TEXT NOT NULL,
gender ENUM('SECRET', 'MEN', 'WOMEN'),
weekday INT,
hour INT,
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_weekday (weekday, hour, createdAt DESC),
INDEX idx_categoryId (categoryId, createdAt DESC),
);
This is the table I am creating.
When deploying to amplify, an error occurs if the following items are present.
.identifier([
"id"
])
You can deploy by manually deleting these, but this ignores the following advice.
/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */
Is this issue under investigation?
Hi @rnrnstar2 Apologies for the delay, thank you for the info!
I will be trying to reproduce this issue today and will report back with any findings
Environment information
Description
An error occurs when an enum is set as a required column.
error message
Property 'required' does not exist on type 'EnumType<readonly ["SECRET", "MEN", "WOMEN"]>'. ts(2339)