I just added a new model to existing data: ```mod...
# orm-help
a
I just added a new model to existing data:
Copy code
model Settings {
  id       String @id @default(cuid())
  timezone String @default("UTC")
  user     User[]
}
It threw migration error so I used
--create-only
but don't know how to fix it. I've been redirected to https://pris.ly/d/migrate-resolve but don't see anything there that helps me. The error is:
Copy code
Applying migration `20211114104346_create_settings`
Error: P3018

A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>

Migration name: 20211114104346_create_settings

Database error code: 23502

Database error:
ERROR: column "settingsId" of relation "User" contains null values

DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("23502"), message: "column \"settingsId\" of relation \"User\" contains null values", detail: None, hint: None, position: None, where_: None, schema: Some("public"), table: Some("User"), column: Some("settingsId"), datatype: None, constraint: None, file: Some("tablecmds.c"), line: Some(5815), routine: Some("ATRewriteTable") }
How do I fix it?
r
@Akshay Kadam (A2K) 👋 Your
settingId
in the
User
model must be nullable as you already have existing data.
a
So what's the fix?
Do I have to make it optional like
settingsId?
I mean I've never done db migrations with existing data
And the docs don't really answer anything in detail. Its just a overview
r
Yes it should be optional.
👍 1
a
So I make it optional first, then I change the database manually & when the values are not null, I can revert back to make it not optional, right?
r
Yes, make it optional first, seed the optional field and change the field to be required.
👍 1