<?php
Use Illuminate\database\schema\blueprint;
Use illuminate\database\migrations\migration;
Class Artical extends migration
{
This method for itself to determine whether the database index exists, $table table name, $name index name, can be called in this file using the
Public Function Hasindex ($table, $name)
{
$conn = Schema::getconnection ();
$dbSchemaManager = $conn->getdoctrineschemamanager ();
$doctrineTable = $dbSchemaManager->listtabledetails ($table);
Return $doctrineTable->hasindex ($name);
}
/**
* Run the migrations.
*
* @return void
*/
Public function up ()
{
Create a Table article table
if (! Schema::hastable (' article ')) {//Determine if the article table exists
Schema::create (' article ', function (Blueprint $table) {
$table->increments (' id ');
$table->string (' email ')->default (' [email protected] ')->nullable ()->comment (' email ');
$table->char (' password ', +)->comment (' Password ');
$table->string (' title ')->comment (' titles ');
$table->timestamps ();//Add a field for creation time and a field to modify time
$table->remembertoken ();
$table->engine = ' MyISAM ';
});
}else{
2016/3/5 Alpine
if (! Schema::hascolumn (' article ', ' Sex ')} {//Determine if the column exists and does not exist create this column
Schema::table (' article ', function ($table) {
$table->tinyinteger (' Sex ')->default (' 1 ')->comment (' Gender ');
});
}
2016/3/7 Alpine
if (Schema::hascolumn (' article ', ' title ')) {//Judgment column modifies the properties of its field if it exists
Schema::table (' article ', function ($table) {
$table->text (' title ')->change ();
});
}
2016/3/9 Alpine
if (Schema::hascolumn (' article ', ' Remember_token ')) {//If there are remember_token columns in the article table then delete
Schema::table (' article ', function ($table) {
$table->dropcolumn (' Remember_token ');
});
}
}
}
/**
* Reverse the migrations.
*
* @return void
*/
Public function Down ()
{
Delete an article table
Schema::d rop (' article ');
}
}
This article from "Mountain" blog, declined reprint!
Demo of laravel5.1 Database migration file