Intro

Creating a project

# mix phx.new <name>
mix phx.new my_app

Options

--live include LiveView
--database possible values are: postgres, mysql, mssql
--no-webpack  
--no-ecto  
--no-html  
--no-gettext  
--no-dashboard do not include Phoenix.LiveDashboard
--install will fetch and install dependencies (including npm js)
--no-install  

Generators

migration

# mix ecto.gen.migration <migration name>
mix ecto.gen.migration add_posts_table

Other generators

schema

# mix phx.gen.schema <schema module> <plural model name> <attributes>
mix phx.gen.schema Blog.Post blog_posts title:string views:integer

This command will create the following files:

Attribute types

user_id:references:users will result in a migration with an :integer column of :user_id and create an index.

tags:array:string will create an array type if the database supports it.

Unique columns can be generated with title:unique or unique_int:integer:unique

Options

--table cms_posts change the name of the generated table
--no-migration  

context

# mix phx.gen.context <context> <schema> <plural schema> <attributes>
mix phx.gen.context Accounts User users name:string age:integer

This command will create the following files:

Options

--table cms_posts change the name of the table generated
--no-schema  
--no-migration  

html

# mix phx.gen.html <context> <schema> <plural schema> <attributes>
mix phx.gen.html Accounts User users name:string age:integer

This command will create the following files:

Options

--no-context  
--no-schema  

json

# mix phx.gen.html <context> <schema> <plural schema> <attributes>
mix phx.gen.json Accounts User users name:string age:integer

This command will create the following files:

Options

live

# mix phx.gen.live <context> <schema> <plural schema> <attributes>
mix phx.gen.live Accounts User users name:string age:integer

This command will create the following files:

Options

--no-context  
--no-schema  

Dynamic Forms

Resources

Blog posts