Как написать миграцию для добавления колонки?
namespace WebApiServer.Migrations
{
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
public partial class AddFieldAvatarToUsersTable : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
// alter table users alter column add Avatar - varchar(255)
}
protected override void Down(MigrationBuilder migrationBuilder)
{
// alter table users alter column drop Avatar
}
}
}
Например как в PHP (Laravel)
class AddFieldAvatarToUsersTable extends Migration
{
/**
* Run the migration.
*
* @return void
*/
public function up()
{
Schema::table('users', function(Blueprint $table){
$table->string('avatar')->default('default.jpg');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('avatar');
});
}
}