如何在包管理器中执行迁移?
How to perform migrations in the package manager?
我安装了 FluentMigration 来管理我的 SQL 个文件。
在包管理中我执行以下命令:
PM> dotnet add package FluentMigrator
PM> dotnet add package FluentMigrator.Runner
迁移
[Migration(201805041513)]
public class _201805041513_CriacaoTabelaPessoa : ForwardOnlyMigration
{
public override void Up()
{
Create.Table("Pessoa")
.InSchema("angularCore")
.WithColumn("Id").AsInt32().Identity()
.WithColumn("Nome").AsString(80)
.WithColumn("SobreNome").AsString(50)
.WithColumn("Email").AsString(50)
.WithColumn("IdTpoPessoa").AsInt16()
.WithColumn("IdEndereco").AsInt16();
}
}
进程外(针对某些公司要求)
PM> dotnet tool install -g FluentMigrator.DotNet.Cli
错误:
No executable found corresponding to the "dotnet-tool" command
Documentation
编辑
运行 在
PM> dotnet tool install -g FluentMigrator.DotNet.Cli
PM> dotnet fm migrate -p sqlite -c "Data Source=test.db" -a ".\bin\Debug\netcoreapp2.1\test.dll"
生成teste.db
In the old versions you run the migrations directly in the database, I
did not understand how to update my database, ie create the Person
table through the generated test.db file?
我能够毫无问题地使用它。这是我所做的:
首先我安装了.NET Core 2.1-Preview 2。安装后我验证了版本:
dotnet --version
2.1.300-preview2-008533
然后我创建了项目
mkdir testfm
cd testfm
dotnet new console
安装了 nuget 包
dotnet add package FluentMigrator
dotnet add package FluentMigrator.Runner
dotnet add package FluentMigrator.Runner.SQLite
dotnet add package Microsoft.Data.Sqlite
安装了 CLI 工具
dotnet tool install -g FluentMigrator.DotNet.Cli
创建了一个名为 Migration1.cs
的迁移 Class
using FluentMigrator;
namespace test
{
[Migration(201805041513)]
public class _201805041513_CriacaoTabelaPessoa : ForwardOnlyMigration
{
public override void Up()
{
Create.Table("Pessoa")
.InSchema("angularCore")
.WithColumn("Id").AsInt32().Identity()
.WithColumn("Nome").AsString(80)
.WithColumn("SobreNome").AsString(50)
.WithColumn("Email").AsString(50)
.WithColumn("IdTpoPessoa").AsInt16()
.WithColumn("IdEndereco").AsInt16();
}
}
}
编译项目
dotnet build
运行从项目根目录迁移
dotnet fm migrate -p sqlite -c "Data Source=test.db" -a
".\bin\Debug\netcoreapp2.1\test.dll"
然后我收到了以下消息。
然后我通过查看 SqlLite DB
确认 table 已创建
要 运行 在 Sql Server 2016 上执行相同的迁移,您将 运行:
dotnet fm migrate -p SqlServer2016 -c
"server=SQLSERVERINSTANCE;uid=testfm;pwd=test;Trusted_Connection=yes;database=FluentMigrator"
-a ".\bin\Debug\netcoreapp2.1\test.dll"
我安装了 FluentMigration 来管理我的 SQL 个文件。
在包管理中我执行以下命令:
PM> dotnet add package FluentMigrator
PM> dotnet add package FluentMigrator.Runner
迁移
[Migration(201805041513)]
public class _201805041513_CriacaoTabelaPessoa : ForwardOnlyMigration
{
public override void Up()
{
Create.Table("Pessoa")
.InSchema("angularCore")
.WithColumn("Id").AsInt32().Identity()
.WithColumn("Nome").AsString(80)
.WithColumn("SobreNome").AsString(50)
.WithColumn("Email").AsString(50)
.WithColumn("IdTpoPessoa").AsInt16()
.WithColumn("IdEndereco").AsInt16();
}
}
进程外(针对某些公司要求)
PM> dotnet tool install -g FluentMigrator.DotNet.Cli
错误:
No executable found corresponding to the "dotnet-tool" command
Documentation
编辑
运行 在
PM> dotnet tool install -g FluentMigrator.DotNet.Cli
PM> dotnet fm migrate -p sqlite -c "Data Source=test.db" -a ".\bin\Debug\netcoreapp2.1\test.dll"
生成teste.db
In the old versions you run the migrations directly in the database, I did not understand how to update my database, ie create the Person table through the generated test.db file?
我能够毫无问题地使用它。这是我所做的:
首先我安装了.NET Core 2.1-Preview 2。安装后我验证了版本:
dotnet --version
2.1.300-preview2-008533
然后我创建了项目
mkdir testfm
cd testfm
dotnet new console
安装了 nuget 包
dotnet add package FluentMigrator
dotnet add package FluentMigrator.Runner
dotnet add package FluentMigrator.Runner.SQLite
dotnet add package Microsoft.Data.Sqlite
安装了 CLI 工具
dotnet tool install -g FluentMigrator.DotNet.Cli
创建了一个名为 Migration1.cs
的迁移 Class using FluentMigrator;
namespace test
{
[Migration(201805041513)]
public class _201805041513_CriacaoTabelaPessoa : ForwardOnlyMigration
{
public override void Up()
{
Create.Table("Pessoa")
.InSchema("angularCore")
.WithColumn("Id").AsInt32().Identity()
.WithColumn("Nome").AsString(80)
.WithColumn("SobreNome").AsString(50)
.WithColumn("Email").AsString(50)
.WithColumn("IdTpoPessoa").AsInt16()
.WithColumn("IdEndereco").AsInt16();
}
}
}
编译项目
dotnet build
运行从项目根目录迁移
dotnet fm migrate -p sqlite -c "Data Source=test.db" -a ".\bin\Debug\netcoreapp2.1\test.dll"
然后我收到了以下消息。
然后我通过查看 SqlLite DB
确认 table 已创建要 运行 在 Sql Server 2016 上执行相同的迁移,您将 运行:
dotnet fm migrate -p SqlServer2016 -c "server=SQLSERVERINSTANCE;uid=testfm;pwd=test;Trusted_Connection=yes;database=FluentMigrator" -a ".\bin\Debug\netcoreapp2.1\test.dll"