LoginSignup
1
0

More than 5 years have passed since last update.

【Laravelメモ⑧】データベースのマイグレーションメモ

Last updated at Posted at 2017-03-05

前提

  • MySQL

メモ

事前に必要な設定

  • DB接続関連
    • .env
    • config/database.php
    • php.ini
      • PDO(MySQL)関連
  • データベースは作っておく(create database xxx)

テーブルの作成

マイグレーションファイルの作成

>php artisan make:migration create_init_table

テーブルの定義

  • database/migrationsの下に定義用のファイルが出来ているので、それに定義を書く
class CreateInitTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('test', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('test');
            //$table->timestamps();
        });
    }

マイグレーション

>php artisan migrate

テーブルの変更(カラムの追加)

追加のマイグレーションファイル作成

>php artisan make:migration add_time_create_init_table

テーブル定義の変更(タイムスタンプを追加)

    public function up()
    {
        //
        Schema::table('test', function(Blueprint $table){
            $table->timestamps();
        });
    }

マイグレーション

>php artisan migrate
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0