eaigner / hood

Database agnostic ORM for Go
MIT License
710 stars 52 forks source link

panic: CreateTable can only be invoked inside a transaction #55

Closed zhenweiwang1990 closed 11 years ago

zhenweiwang1990 commented 11 years ago

I have move the CreateTable calling behind the tx := hd.Begin(),I still get an error

panic: CreateTable can only be invoked inside a transaction
eaigner commented 11 years ago

That's because you do hd.CreateTable(&Fruit{}) instead of tx.CreateTable(&Fruit{})

d-reinhold commented 11 years ago

I guess the real question is why does the example in the README use hd.CreateTable(&Fruit{}) outside of the transaction scope? Is that no longer correct?

eaigner commented 11 years ago

When the table is created, no transaction has been started. Where do you see a declaration of tx before hd.CreateTable?

d-reinhold commented 11 years ago

It isn't, and when the example is run, it fails with this error: panic: CreateTable can only be invoked inside a transaction.

eaigner commented 11 years ago

Oh, I see. Must be a relic of the past.