You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One or more columns are added to table "social_post" which cannot be added in a table migration.
The complete table will be deleted and recreated.
I just added one bool column. Nothing special. Why on earth did the whole table have to be dropped? Is this because of the lack of default values (#1140)? If so, this is crazy -- #1140 needs to be implemented.
I saw this, too @lukehutch. It's possible that you added a NOT NULL column, which the migration system can of course not handle. (I'm actually not sure if this is WHY Serverpod defaults to that behavior).
I got around this by rewriting the generated migration.sql file to instead add a nullable column, seed values into every row, and then modify the schema to add a NOT NULL constraint.
A key thing to remember is that you're free to completely rewrite the initial SQL in migration.sql as needed.
Not really, because the next time you try to generate a migration, Serverpod will try to revert any changes you manually made in the previous migration.
The reason Serverpod does this is because there is no support for default values for non-bulla le columns yet.
Is this because of the lack of default values (#1140)?
This is correct. For any database, if you would like to add a non nullable column to a table a default value would be required. And since we don't support default values in the framework yet, we can't support adding a non nullable column in a single migration step.
This is an important feature we are trying to prioritize.
The current recommended workflow given the limitation of not having a default values is:
Add the column as nullable in the model, create a migration and apply it to the database.
Seed the column in whatever way possible (either you could add SQL code to the migration that adds the column or you could manually seed it some way through direct queries).
Drop the nullability of the column in the model, create a migration using the --force flag and apply it to the database.
We still display a warning on step 3 since the migration will fail if all entries don't have a value at that state.
Will close this issue as this is a consequence of lacking support for default values that is already tracked here: #1140.
And this specific case is already identified as a comment in the other issue: #1140 (comment)
@SandPod
What is the recommended workflow for adding a new relation?
"The "nullable" property is not allowed for relation type. Valid keys are {parent, field, onUpdate, onDelete, optional, name}." - serverpod error in the spy.yaml
I also attempted by adding "optional" to the relation, but that also is requiring me to drop the table.
# user.yamlclass: Usertable: userfields:
customIdField: int? # <-- Set this fieldaddress: Address?, relation(optional, field=customIdField)
Although this seems more like a bug, since making the object relation optional should result in this underneath. Could you test if this work and open a dedicated issue for it?
Activity
craiglabenz commentedon Mar 10, 2024
I saw this, too @lukehutch. It's possible that you added a
NOT NULLcolumn, which the migration system can of course not handle. (I'm actually not sure if this is WHY Serverpod defaults to that behavior).I got around this by rewriting the generated
migration.sqlfile to instead add a nullable column, seed values into every row, and then modify the schema to add aNOT NULLconstraint.A key thing to remember is that you're free to completely rewrite the initial SQL in
migration.sqlas needed.lukehutch commentedon Mar 10, 2024
Not really, because the next time you try to generate a migration, Serverpod will try to revert any changes you manually made in the previous migration.
The reason Serverpod does this is because there is no support for default values for non-bulla le columns yet.
SandPod commentedon Mar 11, 2024
This is correct. For any database, if you would like to add a non nullable column to a table a default value would be required. And since we don't support default values in the framework yet, we can't support adding a non nullable column in a single migration step.
This is an important feature we are trying to prioritize.
The current recommended workflow given the limitation of not having a default values is:
--forceflag and apply it to the database.We still display a warning on step 3 since the migration will fail if all entries don't have a value at that state.
Will close this issue as this is a consequence of lacking support for default values that is already tracked here: #1140.
And this specific case is already identified as a comment in the other issue: #1140 (comment)
develocode777 commentedon Mar 11, 2024
This solution does not work. It still shows the warning after manually adding the column, seeding it and making it non nullable.
SandPod commentedon Mar 11, 2024
The
--forceflag is required in step 3 since we still display a warning.SandPod commentedon Mar 11, 2024
Sorry, I understand the confusion now. I will update the instructions to make the steps a bit more clear.
develocode777 commentedon Mar 11, 2024
Ah, I get it now, it works, thanks.
shawnAshton commentedon Feb 5, 2026
@SandPod
What is the recommended workflow for adding a new relation?
"The "nullable" property is not allowed for relation type. Valid keys are {parent, field, onUpdate, onDelete, optional, name}." - serverpod error in the spy.yaml
I also attempted by adding "optional" to the relation, but that also is requiring me to drop the table.
marcelomendoncasoares commentedon Feb 6, 2026
@shawnAshton Have you tried creating the relation with
optionaland specifying the foreign key field, so that you can set the field as nullable explicitly?Although this seems more like a bug, since making the object relation optional should result in this underneath. Could you test if this work and open a dedicated issue for it?