How to Create an Empty Phoenix Application

From ElixirBlocks
Jump to: navigation, search

Before You Begin

Installing Phoenix

This article assumes that you have installed the Phoenix web framework and all its dependencies correctly without errors. If you have not installed the Phoenix web framework please view the documentation here



What you will do

  • Create a new Phoenix application instance


Create the App

Select a directory, open a terminal and type:

mix phx.new app


This creates a new phoenix application named "app".

The terminal will prompt you to download dependencies, select Y for yes.

Fetch and install dependencies? [Yn] y

When dependency downloading is complete, you have the choice to connect your app to a database using the following command.


mix ecto.create

If you run the command, Elixir will try to connect to your app to your instance of PostgresSQL and create a new database. Phoenix defaults to naming your database the same name as your app with a suffix of _dev appended to it.


In other words,if your application name is app, Phoenix will try to create a database named

 app_dev 

. If you application is named todos then Phoenix defaults to creating a database named

 todos_dev 

.

Before you run mix ecto.create you can change the database name Phoenix creates for you. You can also change the credentials that Phoenix uses in attempting to connect to your database.

The file that contains this information is:

  
 name-of-app/config/dev.exs


The relevant part of the code in dev.exs is here:

  

config :app, App.Repo,
  username: "postgres",
  password: "postgres",
  hostname: "localhost",
  database: "app_dev",

The database name in the above code can be changed to anything you want. The username and password fields need to match your PostgresSQL installation. If they don't match, Phoenix won't be able to connect to PostgresSQL and your app will be created without a database.


Create the Database

Enter the database creation command:

  
mix ecto.create

If you get an error check your Database credentials.

More Information on Database Table Creation

This page is in progress

How to Create Database Seed Data in Elixir Phoenix