Crear migrations en Laravel
Crear migraciones en Laravel
Laravel recomienda añadir al nombre del migration el prefijo create_ y el sufijo _table. Es decir que un migration con nombre professions pasa a ser create_professions_table como se muestra a continuación.
Crear migration
php artisan make:migration create_[migration]_table
Ejemplo de migration professions
php artisan make:migration create_professions_table
Con el comando anterior se origina una archivo con el código que se muestra debajo.De esta forma Laravel crea el siguiente archivo:
phpuse Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;class CreateProfessionsTable extends Migration{/*** Run the migrations.** @return void*/public function up(){Schema::create('professions', function (Blueprint $table) {$table->increments('id');$table->timestamps();});}/*** Reverse the migrations.** @return void*/public function down(){Schema::dropIfExists('professions');}}
Otra forma muy útil de crear un migration es muy similar a la anterior pero se añade la opción create y se indica el nombre de la tabla:
php artisan make:migration new_professions_table --create=professions
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was toolong;max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was toolong; max key length is 767 bytes
Añadir la siguiente línea en el archivo AppServiceProvider.php del directorio app/Providers:
use Illuminate\Support\Facades\Schema;public function boot(){Schema::defaultStringLength(191);}
Para poder comentar es necesario iniciar sesión