scalaslickslick-3.0

Inserting 0 for an auto-incrementing column in mysql


I am using slick 3.2.1

I need to insert "0" into a column which is auto-increment (MySQL).

I wrote this code

val foo = Foo(0, "FOO")
val fooQuery = Tables.FooTable forceInsert  foo
Await.result(db.run(fooQuery), Duration.Inf)

My hope was that forceinsert will put the exact value of 0 in the column rather than using the database provided incremented value.

The code above executes fine. but when I go into DB I see that the ID is 1. So its not forcing the id to 0. it is still using the database provided value.


Solution

  • You will not be able to insert into any auto-incremented column if your value is lower than an existing one. You can do this is if the table in empty I believe.