最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

aws lambda - How to auto increment Primary key ID for a mysql database in AWS Amplify GEN 2 PreSignUpTriggerHandler - Stack Over

programmeradmin0浏览0评论

My Mysql schema for a database table is given below, which is generated by using the following command

npx ampx generate schema-from-database --connection-uri-secret SQL_CONNECTION_STRING --out amplify/data/schema.sql.ts

schema({
    "user_profiles": a.model({
        id: a.integer().required(),
        email: a.string(),
        profile_owner: a.string(),
        user_type: a.string(),
    }).identifier([
        "id"
    ])
});

My requirement is to add details to user_profiles table in mysql table inside PreSignUpTriggerHandler of cognito registration flow. The problem is that , I need to get the primary key as autoincremented, But I couldn'nt make that, It is asking that the id field should be mandatory My handler code is given below, Can someone help me out to figure out this issue

export const handler: PreSignUpTriggerHandler = async (event) => {
    
    await client.models.UserProfile.create({
        id: 1, //This should be auto incremented
        email: event.request.userAttributes.email,
        user_type: event.request.userAttributes['custom:user_type'],
        profile_owner: `${event.userName}`,
    });

}
发布评论

评论列表(0)

  1. 暂无评论