Skip to content

How to add initial data to table in OnCreate method #1206

Answered by simolus3
mytc asked this question in Q&A
Discussion options

You must be logged in to vote

If I understand correctly the Custom Insert query statement need to run after m.createAll();, right?

Yes, that is correct. Otherwise the table wouldn't exist. To me, it looks like you have a syntax error in your insert statement, AFAIK sqlite does not support [ and ] for column names which explains why no data is being added.

Note that in recent moor versions you can use the regular apis inside a migration callback, so maybe you prefer writing

onCreate: (Migrator m) async {
  await m.createAll();
  await into(users).insert(...);
},

Note that you may have to clear your app's data for this to work now since the db likely already exists. Still, it's a bit worrying that you didn't get an ex…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mytc
Comment options

@simolus3
Comment options

@mytc
Comment options

Answer selected by mytc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants