Skip to content

Documentation Example Missing .to_owned() Call in Migration Examples #140

@caipeter888

Description

@caipeter888

Description

The migration documentation at Writing Migration contains code examples that are missing a necessary .to_owned() call. This omission causes a compile-time type mismatch error when trying to create tables.

Steps to Reproduce

  1. Copy the code example from the documentation (see below).
  2. Attempt to compile the migration.
manager
    .create_table(
        Table::create()
            .table(Post::Table)
            .if_not_exists()
            .col(pk_auto(Post::Id))
            .col(string(Post::Title))
            .col(string(Post::Text))
            .col(enumeration_null(Post::Category, Alias::new("category"), Category::iter()))
    )
    .await

Expected Behavior

The code example should compile without errors.

Actual Behavior

Error Message Received:

error[E0308]: mismatched types
  --> migration\src\m20220101_000001_create_table.rs:37:17
   |
36 |               .create_table(
   |                ------------ arguments to this method are incorrect
37 | /                 Table::create()
38 | |                     .table(Post::Table)
39 | |                     .if_not_exists()
40 | |                     .col(pk_auto(Post::Id))
...  |
46 | |                         Category::iter(),
47 | |                     )),
   | |______________________^ expected `TableCreateStatement`, found `&mut TableCreateStatement`

Workaround

Appending .to_owned() to the table creation chain fixes the issue. For example:

manager
    .create_table(
        Table::create()
            .table(Post::Table)
            .if_not_exists()
            .col(pk_auto(Post::Id))
            .col(string(Post::Title))
            .col(string(Post::Text))
            .col(enumeration_null(
                Post::Category,
                Alias::new("category"),
                Category::iter(),
            ))
            .to_owned(),
    )
    .await

Versions

└── sea-orm-migration v1.1.4
    ├── sea-orm v1.1.4
    │   ├── sea-orm-macros v1.1.4 (proc-macro)
    │   │   ├── sea-bae v0.2.1 (proc-macro)
    │   ├── sea-query v0.32.1
    │   │   └── sea-query-derive v0.4.2 (proc-macro)
    ├── sea-orm-cli v1.1.4
    │   ├── sea-schema v0.16.1
    │   │   ├── sea-query v0.32.1 (*)
    │   │   └── sea-schema-derive v0.3.0 (proc-macro)
    ├── sea-schema v0.16.1 (*)
    - OS: Windows 10.0.26100 x86_64 (X64)
    ✔ MSVC: Visual Studio 生成工具 2022
    ✔ rustc: 1.84.1 (e71f9a9a9 2025-01-27)
    ✔ cargo: 1.84.1 (66221abde 2024-11-19)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions