r/adonisjs • • Oct 27 '26

Beginner Coder: Stuck with a db error

Hi,

I'm working on an adonisjs project. l've ran into an error

My project is on github:

https://github.com/Ajaz754/adonisjs-project-22-.git

The error is in file 'database/seeders/ product_seeder.ts' Line 10

The error is:

Object literal may only specify known properties, and 'userld' does not exist in type
'OneOrMany<Partial<ModelAttributes<Product>>>.

Adding 'userId' field to the product schema and rerunnning migration did not fix the issue.

I think it may have something to do with this (something I tried in the REPL):

> (js) const user = await models.user.find(1)
Uncaught SyntaxError: Identifier 'user' has already been declared
> (js) user.id
Uncaught ReferenceError: user is not defined
> (js)

I don't understand. Please correct me if I'm wrong but it says 'user' already exists but when I try to use it, it says its undefined?

Any help would be much appreciated

TIA

1 Upvotes

10 comments sorted by

3

u/Aceventuri Oct 27 '26

You have a mix of user.id, user_id and userId in your migrations. Make them all snake case. Db field names should be snakecase and adonis will autoconvert to camelCase in the schema.

2

u/Aceventuri Oct 27 '26

Do rollback or fresh migration of course

1

u/Capable_Square7319 Oct 27 '26

Yeah it was me. I wasn’t migrating properly and the correct files. Issues gone now. Appreciate the help bro

2

u/elconcarne Oct 27 '26

I don’t see userId in the product table in the schema

2

u/Capable_Square7319 Oct 27 '26

Yes you’re right, sorry. I wasn’t migrating properly. All fixed now. Thanks, appreciate the help

2

u/elconcarne Oct 27 '26

Did you run the migration?

2

u/elconcarne Oct 27 '26

Also, make sure the column matches all places it exists. And doesn’t have camelcase where it shouldn’t

1

u/Capable_Square7319 Oct 27 '26

I ran "node ace migration:run" and it came back successful

1

u/Capable_Square7319 Oct 27 '26

table.integer('userId').notNullable()

Is that camelcase correct?

2

u/elconcarne Oct 27 '26

Yea. Sorry. I should have elaborated further. I ran into a similar issue a while back and the casing didn’t match between the user model and the lookup reference I added to the other model. I think I put snake casing or something in the other models lookup reference