Closed bxcodec closed 7 years ago
After the models generated, i got the error when i test the models.
*ps, could you create topic on stackoverflow.com please ?? My reputation not enough to create new topic/tag.
**ps : sorry for my bad grammar, and bad name's column that using a little my local language.
Yes, the problem here is that "kota" according to our pluralization library is the plural of "kotum". So it tries to singularize your column name in one area and that breaks it.
We will most likely fix this by tomorrow and release a minor version update to deal with it. For now you can apply this patch:
diff --git a/strmangle/inflect.go b/strmangle/inflect.go
index 78945b6..8499bda 100644
--- a/strmangle/inflect.go
+++ b/strmangle/inflect.go
@@ -184,5 +184,6 @@ func newBoilRuleset() *inflect.Ruleset {
rs.AddIrregular("move", "moves")
rs.AddIrregular("zombie", "zombies")
rs.AddIrregular("cookie", "cookies")
+ rs.AddUncountable("kota")
return rs
}
One reason I'm asking you to try this patch, is to see if you can find any other problems before we release this patch. Better to fix many problems at once :)
Well, thanks for fast response. Maybe i need to try more. And of course , i need "more documentation" :)
How to deal with null.*Datatypes ? I don't see on your documentation , any explanation about this.
for example this is the model:
`type OkAkun struct {
IDAkun int `boil:"id_akun" json:"id_akun" toml:"id_akun" yaml:"id_akun"`
Username null.String `boil:"username" json:"username,omitempty" toml:"username" yaml:"username,omitempty"`
PhoneNumber null.String `boil:"phone_number" json:"phone_number,omitempty" toml:"phone_number" yaml:"phone_number,omitempty"`
Email null.String `boil:"email" json:"email,omitempty" toml:"email" yaml:"email,omitempty"`
CreateAt null.Time `boil:"create_at" json:"create_at,omitempty" toml:"create_at" yaml:"create_at,omitempty"`
UpdateAt null.Time `boil:"update_at" json:"update_at,omitempty" toml:"update_at" yaml:"update_at,omitempty"`
Password null.String `boil:"password" json:"password,omitempty" toml:"password" yaml:"password,omitempty"`
R *OkAkunR `boil:"-" json:"-" toml:"-" yaml:"-"`
L OkAkunL `boil:"-" json:"-" toml:"-" yaml:"-"`
}`
And when i try to insert,
i got error's like this, (this happen on all null.*Datatypes )
cannot use "bxcodec@gmail.com" (type string) as type null.String in field value
Can you show the line that's causing this? Also check out the documentation for the null package we use: https://godoc.org/gopkg.in/nullbio/null.v6
This shouldn't happen unless there's some problem with the struct generation. Can you show me the "show create table" from mysql for that table? Alternatively show the relevant part of the output when you run sqlboiler --debug mysql
This is the Sql :
CREATE TABLE `OkAkun` (
`id_akun` int(11) NOT NULL AUTO_INCREMENT COMMENT ' ',
`username` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`phone_number` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`email` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`create_at` datetime DEFAULT NULL,
`update_at` datetime DEFAULT NULL,
`password` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id_akun`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
this is how i tried to insert data :
a := &models.OkAkun{
Username : "bxcodec",
PhoneNumber: "882292348292",
Email : "bxcodec@gmail.com",
}
if err := a.Insert(db); err != nil {
log.Error("Failed TO Insert Akun", "err", err);
}
I also asked for the line of code that is causing the error, that is essential in order to figure out what's going on :)
I've update my comment
Yes, you have to use the null package helpers. I suggest null.StringFrom
: https://godoc.org/gopkg.in/nullbio/null.v6#StringFrom
a := &models.OkAkun{
Username: null.StringFrom("bxcodec"),
PhoneNumber: null.StringFrom("882292348292"),
Email: null.StringFrom("bxcodec@gmail.com"),
}
if err := a.Insert(db); err != nil {
log.Error("Failed TO Insert Akun", "err", err);
}
But the bigger problem is that you should NOT have these as nullable in your database. That's a very bad database design, please change your table so that these fields cannot be null.
Yeahh... I just figured it after i do show create table
. But, look for the positive, now i can deal with the null-able column :D
Thanks for the response, and I hope, this is also documented as soon as the development process.
I got this error when i'm test the models. Fyi, i'm using mysql
This happens only for table that use 2 same foreign keys
for example sample.sql