-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Defining index for a model in @model decorator #2753
Comments
@model()
export class Model extends Entity {
@property({type: 'number', id: true , generated: true }) id: number; // id true for using it as an index and generated true to increment automatically in db.
} About having several indexes I am not sure if using unique still works. I will test later this weekend I guess. |
Based on the log, we are executing the following SQL command to create the index: ALTER TABLE `CashtokenTransaction`
ADD UNIQUE INDEX `cashtoken_transaction_index`
(internal_ref,external_ref)', The database responds with the following error:
What SQL data types are used by (A side note: we are looking into a more ergonomic syntax for defining indexes, see #2712. The issue described here is not related to LoopBack syntax though.) |
Hello @bajtos |
We need to find out how is loopback-connector-mysql mapping @rkterungwa16 is there any limit on the size of your @model()
class MyModel extends Entity {
@property({
type: 'string',
length: 1024
})
internal_ref: string
// etc.
} You can find the exact column size in the debug log - look for the SQL statement |
@rkterungwa16, we think the above comment has answered your question, so I'd like to close this issue now. Thanks. |
To configure the @model decorator and define index for a model, the loopback4 documentation refers us to loopback3. In the loopback3 documentation, the recommended format for model configuration is as shown below:
However this throws an error on creating a migration (see below). My datasource is SQL.
When I modify the configuration object as shown below:
Migration works fine.
The text was updated successfully, but these errors were encountered: