Good day, everyone. I've been using exposed for a ...
# exposed
a
Good day, everyone. I've been using exposed for a while and it's been great. I ran into an issue today. I removed a column from my table declaration and I ran the project again. However, even though I'm using the
Copy code
SchemaUtils.createMissingColumnAndSchemas()
option, I am getting a error of missing default value in that exact column I removed when trying to inset a new record. Thanks in advance.
a
Are you running against a persistent database (i.e. not in memory)? If so, and if I'm understanding the problem correctly, then even though you removed the column from your exposed table declaration, the columns still exists in the real table, so the table requires a value to insert a new row. Here's a few options: 1. Perform a schema change on the real database table to remove the column (assuming you won't miss the data that's already there) 2. Perform a schema change on the real database table to make the column nullable, or have a default value 3. Delete the real database table (if you won't miss whatever data is already there) 4. Add the column back to your exposed table definition, and set a default value at runtime with
clientDefault
a
Thanks for your response. Yes, I'm using a persistent database: MySQL. As for your suggestions, is option 1 and 2 something I can do using exposed or does it have to be done from outside e.g MySQL shell? For now, I drop the tables and recreate them on App Initialization.
a
1 and 2 would most likely be done with the MySQL shell, or with a purpose-built schema change tool, like Flyway. Someone please correct me if Exposed can do this now.
a
Okay. Thanks. I'll do my research of Flyway soon.
a
For what it's worth, if you were using exposed to update your schemas, then a full schema migration tool like Flyway may be overkill.
104 Views