Ƙirƙirar da Gudanar da Databases tare da Migration s in Laravel

A cikin Laravel, samar da ingantacciyar hanya don ƙirƙira da sarrafa bayanan s. suna kama da sarrafa sigar don bayananku, yana ba ku damar canza tsarin bayanai akan lokaci da kuma lura da canje-canje. Anan ga jagorar mataki-mataki akan amfani a cikin: migrations schema Migrations migrations Laravel

 

Ƙirƙirar a Migration

Don ƙirƙirar sabon migration, zaku iya amfani da umarnin Artisan. Misali, don ƙirƙirar don ƙirƙirar tebur, gudanar da umarni mai zuwa: make:migration migration users

php artisan make:migration create_users_table

 

Ma'anar da Schema

Bude migration fayil ɗin da aka ƙirƙira a cikin  kundin adireshi. A cikin hanyar, zaku iya ayyana teburin ku ta amfani da magini. Misali, don ƙirƙirar tebur tare da ginshiƙai, zaku iya amfani da hanyar: database/migrations up schema Laravel schema users name email create

Schema::create('users', function(Blueprint $table) {  
    $table->id();  
    $table->string('name');  
    $table->string('email')->unique();  
    $table->timestamps();  
});  

 

Gudu Migrations

Don aiwatar da kuma ƙirƙirar tebur masu dacewa a cikin bayanan, yi amfani da umarnin Artisan: migrations migrate

php artisan migrate

 

Rollback

Idan kana buƙatar soke wani migration, zaka iya amfani da umarnin. Wannan zai dawo da rukuni na ƙarshe na: migrate:rollback migrations

php artisan migrate:rollback

 

Migration Matsayin Gudanarwa

Laravel yana ci gaba da bin diddigin abin da aka aiwatar ta hanyar amfani da tebur a cikin bayanan. Kuna iya amfani da umarnin don ganin matsayin kowane: migrations migrations migrate:status migration

php artisan migrate:status

 

Tables masu gyarawa

Idan kana buƙatar gyara tebur mai gudana, zaku iya ƙirƙirar sabo migration ta amfani da umarnin kuma amfani da hanyoyin maginin kamar, , ko don yin canje-canje masu dacewa. make:migration schema addColumn renameColumn dropColumn

 

Yin amfani da a cikin yana ba da tsari da ingantaccen hanya don ƙirƙira da sarrafa bayanan s. Ta amfani da nau'ikan sarrafawa-kamar ayyuka, zaku iya yin canje-canje a tsarin bayananku cikin sauƙi kuma ku lura da waɗannan canje-canjen akan lokaci. migrations Laravel schema