How to specify using a different Repo for mix.gen.context?

Using mix.gen.context defaults to using Appname.Repo for the generated code.

Is there anyway to specify to use another repo, I looked but can’t find any information on this.

My app uses different databases for each context (is this a bad idea?) so it gets a bit bothersome because generating contexts means I have to do lots of manual error prone renaming etc…

I know this thread is from back in 2021, so you may not need the answer anymore — but I just ran into the same thing and figured I’d leave a note here for anyone who comes across it in the future.

When you want a generated context to target a different repo, the flag you’re looking for is –context-app. That way the generator puts the schema/context code into the correct app, rather than the default.

So for example:

mix phx.gen.context Accounts User users name:string --context-app my_other_app

If you are going to use that context app more often than the default, you might consider changing the default app that is being used. It is specified in the generators section inside config.exs

Hope this helps someone else who lands here like I did!