Is it possible to use diesel with tables without primary key? #4717
-
|
I tried the CLI setup to generate structs from tables but the mysql db I'm inhering has many tables without a primary key, which the CLI didn't like. Is this something I can overcome in configuration somehow? Or is diesel just not made for these kinds of databases? Cheers! PS I also have tables that start with numbers, which was a problem when I tried seaorm generate too 🤣 so far diesel hasn't complained about those though. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Diesel-cli currently does not really support emitting a schema.rs file for tables without primary keys. You can workaround that by manually writing the relevant As for the column names starting with a number: You should be able to get these working by using the |
Beta Was this translation helpful? Give feedback.
-
|
Hi, could we expect a feature in the future which would allow us not to define a primary key ? BR. |
Beta Was this translation helpful? Give feedback.
Diesel-cli currently does not really support emitting a schema.rs file for tables without primary keys. You can workaround that by manually writing the relevant
table!macro calls and declaring some column as fake primary keys there.As for the column names starting with a number: You should be able to get these working by using the
#[sql_name = "123abc"]attribute on the relevant column + by choosing a valid rust identifier as column name in thetable!macro invocation.