Closed Rekshot21 closed 1 year ago
Did you change the type of a field between int and string? Was the migration successful or failed?
I didnt change any field from int to string and the migration was succesfull every time.
Table:
Ok I need to test this then. On what version are you?
stormberry: ^0.10.0
Dart: 2.18.3
I will add the print when the query runs in case it helps:
UPDATE "users" SET "name" = COALESCE(UPDATED."name"::text, "users"."name"), "age" = COALESCE(UPDATED."age"::int8, "users"."age") FROM ( VALUES ( @0, @1, @2 ) ) AS UPDATED("id", "name", "age") WHERE "users"."id" = UPDATED."id"
@schultek Hey I was testing this out, it seems the error is when postgres replaces the id parameter it adds the ' and thats why its failing.
So this was the query that was been generated:
UPDATE "users" SET "name" = COALESCE(UPDATED."name"::text, "users"."name"), "age" = COALESCE(UPDATED."age"::int8, "users"."age") FROM ( VALUES ( @0, @1, @2 ) ) AS UPDATED("id", "name", "age") WHERE "users"."id" = UPDATED."id"
The query is okay but when postgress replaces the parameters the @0 goes from the intended int id (for example 1) to a string type (1 will turn into '1').
If I use a String Id it works okay.
Also if I have a field as bigint and postgress does the same thing (for example I try to set a 54 and postgres mades it a '54') it works alright and I have no errors.
I hope being right and that this helps.
Testing made for easier follow up:
Int Id Model
´´´dart
@Model()
abstract class User {
@PrimaryKey()
@AutoIncrement()
int get id;
int get businessId;
String get userName;
String? get email;
String? get phone;
String get password;
UPDATE "users"
SET "business_id" = COALESCE(UPDATED."business_id"::int8, "users"."business_id"), "user_name" = COALESCE(UPDATED."user_name"::text, "users"."user_name"), "email" = COALESCE(UPDATED."email"::text, "users"."email"), "phone" = COALESCE(UPDATED."phone"::text, "users"."phone"), "password" = COALESCE(UPDATED."password"::text, "users"."password"), "role" = COALESCE(UPDATED."role"::text, "users"."role")
FROM ( VALUES ( @0, @1, @2, @3, @4, @5, @6 ) )
AS UPDATED("id", "business_id", "user_name", "email", "phone", "password", "role")
WHERE "users"."id" = UPDATED."id"
´´´
The Query has the right syntax in PgAdmin4
If I input the parameters manually:
It Updates no problem:
If I set the ID as a String manually I have the error above
It might be another thing but from I was testing this is what I found,
hope this helps
Thanks I think I know now how to fix it.
Should be fixed in v0.11.0
FYI
I'm facing this issue in 0.12.1
The error I'm facing is of radix
, if I convert it manually to int
FormatException: Invalid radix-16 number (at character 1)
CC: @schultek
@mhmzdev Can you open a new issue for your problem?
Im having this error when I try to update:
"An exception occurred. PostgreSQLException (PostgreSQLSeverity.error 42883: operator does not exist: integer = text Hint: No operator matches name and types of arguments. Explicit type conversion may need to be added.)"
This is my call:
This is my model:
I did the migration 4 times already, I tried to workaround this by making a get, delete and insert, but I cant specify the Id in the insert either. Am I doing something wrong?