Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Latest commit

 

History

History
60 lines (47 loc) · 2.64 KB

README.md

File metadata and controls

60 lines (47 loc) · 2.64 KB

Fix

In the generated schema you need to import {YourEnumName}Mapping instead of {YourEnumName}.

To prevent having to edit the schema.rs manually, you can re-export the Mapping type to just be called {YourEnumName}. Then add that re-export to the diesel.toml.

Old: problem description

This example is abridged from the Diesel getting started guide.

It tries to make the following (postgres) SQL

up.sql

create type level as enum ('error', 'warn', 'info', 'debug', 'trace');

create table logs (
  id serial primary key,
  severity level not null default 'info'
);

work with Diesel using the diesel-derive-enum crate.

Unfortunately, it will not compile 😢

error[E0277]: the trait bound `types::Level: diesel::Expression` is not satisfied
 --> src\models.rs:4:17
  |
4 | #[derive(Debug, Insertable)]
  |                 ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `types::Level`
  |
  = note: required because of the requirements on the impl of `AsExpression<types::Level>` for `types::Level`
  = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `types::Level: diesel::Expression` is not satisfied
 --> src\models.rs:4:17
  |
4 | #[derive(Debug, Insertable)]
  |                 ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `types::Level`
  |
  = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert types::Level`
  = note: required because of the requirements on the impl of `AsExpression<types::Level>` for `&'insert types::Level`
  = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `types::Level: diesel::Expression` is not satisfied
 --> src\models.rs:4:17
  |
4 | #[derive(Debug, Insertable)]
  |                 ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `types::Level`
  |
  = note: required because of the requirements on the impl of `diesel::Expression` for `&types::Level`
  = note: required because of the requirements on the impl of `AsExpression<types::Level>` for `&types::Level`
  = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `db_enums_test` due to 3 previous errors