Is it possible to create longer strings than `.string` datatype on databases?
Today I got a MySQL error: Server error: Data too long for column 'tasting_notes' at row 1 error.
I assume a .string dataType has a limited size. My schema is defined as:
func prepare(on database: Database) -> EventLoopFuture<Void> {
database.schema("coffee")
.id()
.field("name", .string, .required)
.field("country_code", .string, .required)
.field("process", .string)
.field("varietal", .string)
.field("tasting_notes", .string)
.create()
}
Is there a way to specify a data type longer than a .string?
I was thinking on defining .data and then handling myself the encoding / decoding similar to this issue https://github.com/vapor/fluent/issues/439 but this looks overly complicated
I'm assuming the generated table is VARCHAR(256)? You can provide a custom type, like
.field("tasting_notes", .custom(SQLRaw("VARCHAR(1024)")))
@0xTim this is great! Thank you!
I guess I can wrap that into something like
if let _ = database as? MySQLDatabase {
so I can keep compatibility between my production environment (MariaDB) and my local environment (SQLite)
I mean you can do but I really would recommend using the same DB locally and in production - we've seen way too many issues with people using different DBs