ariga / entimport

A tool for generating Ent schema from SQL schema
Apache License 2.0
184 stars 55 forks source link

invalid primary key - single part key must be present #8

Closed masseelch closed 3 years ago

masseelch commented 3 years ago

What does the above error mean? The table I try to import has a primary key, not partioned.

create table artikel
(
    `Artikel-Id` int auto_increment primary key,
    requires_internal_protocol varchar(255) null
)
    collate = latin1_german2_ci;

Storage engine InnoDB with MySQL 5.7

zeevmoney commented 3 years ago

Hi @masseelch,

I tried your schema with a newer version of MySQL (8.0.26)

and I got the correct output

// Code generated by entimport, DO NOT EDIT.

package schema

import (
    "entgo.io/ent"
    "entgo.io/ent/schema"
    "entgo.io/ent/schema/field"
)

type Artikel struct {
    ent.Schema
}

func (Artikel) Fields() []ent.Field {
    return []ent.Field{field.Int32("id").StorageKey("Artikel-Id"), field.String("requires_internal_protocol").Optional()}
}
func (Artikel) Edges() []ent.Edge {
    return nil
}
func (Artikel) Annotations() []schema.Annotation {
    return nil
}

The tool wasn't tested on older versions, so there might be some issue with the logic or with Atlas (which is used underline). I plan to support older versions (add tests and fix possible bugs) but it's not a top priority at this moment. If you can, please use v8, also you are welcome to contribute.

masseelch commented 3 years ago

Sadyl, I am stuck with 5.7. I have to map by hand then. Thank you for the quick answer :-)

mikestefanello commented 2 years ago

I'm getting the same error with postgres 12.4.