How to fake a primary key which is the sole column in a table?


#1

How to fake a column table which is:

  • the only column in the table
  • the primary key
  • set to auto increment

I tried id: faker.id() but I am getting this error message: TypeError: faker.id is not a function

Thank you


#2

You don’t. It is an auto-incrementing primary key just insert a record and it will be populated.


#3

You are right, but I removed the auto_increment constraint and still can not populate it:
table.integer('id', 10).primary()


#4

I had to use faker.integer() because faker.id() simply does not exist as the error message shows. If you want to understand more, you may check this: https://github.com/adonisjs/adonis-framework/issues/1047