Hello, I’m trying to use UUIDs in a Phoenix project. I’ve got it working, but the controller tests (that previously were green) fail with:
** (ArgumentError) Postgrex expected an integer in -2147483648..2147483647 that can be encoded/cast to type "int4", got <<50, 124, 14, 128, 143, 227, 74, 134, 138, 114, 144, 134, 162, 62, 223, 77>>. Please make sure the value you are passing matches the definition in your table or in your query or convert the value accordingly.
I’ve created a dummy app to illustrate the problem, in the first commit we have a simple Post scaffold, tests pass, on the second I convert the ID to UUID, it works, but the tests fail:
It looks to me like Postgres believes that your UUID column should still be an integer.
If this only happens during testing, make sure you’ve run MIX_ENV=test mix ecto.migrate to ensure that the testing-database is on par with the state of your development database.
Makes sense, to make it work in development, I rolled back and re-run the latest migration; in the test environment then I also needed to do this, or recreate the whole database as well.