前提
- 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