首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dotnet迁移添加“不创建迁移”

Dotnet迁移添加“不创建迁移”
EN

Stack Overflow用户
提问于 2021-08-22 20:15:49
回答 1查看 1.3K关注 0票数 0

因此,我试图更新我的数据库,但是迁移并不是实际创建的,如果我将旧迁移文件夹命名为旧的迁移文件夹,它会更改快照,但不会创建实际的迁移,如果我将另一个文件夹命名为nothing,则不会创建该文件夹。我还处于早期开发阶段(放弃数据库是完全可以接受的),所以我试着把所有的东西都压扁了。

新尝试(我和我的DbContext在同一个项目中)

代码语言:javascript
复制
dotnet ef migrations add Init -o \Migrations\Init -s ..\<StartupLocation>

创建文件夹,创建快照,但不创建实际迁移。

代码语言:javascript
复制
dotnet ef migrations list -s ..\<StartupLocation>

一事无成

代码语言:javascript
复制
dotnet ef database update -s ..\<StartupLocation>

创建一个空数据库..。

我在用SQLite..。

我试着寻找问题,但我遇到了其他问题,有什么想法我可以解决这个问题吗?

清理解决方案不能解决问题。

DbContext

代码语言:javascript
复制
public EcomContext( DbContextOptions<EcomContext> options ) : base( options )
{}
//Fix for nullable reference types
public DbSet<SomeClass> SomeClass => Set<SomeClass>();
//Just a string wrapper with int id and string
public DbSet<StringWrapper> StringWrapperers => Set<StringWrapper>();

protected override void OnModelCreating( ModelBuilder modelBuilder )
{
    modelBuilder.ApplyConfigurationsFromAssembly( 
    Assembly.GetExecutingAssembly() );
    base.OnModelCreating( modelBuilder );
}

SomeClass

代码语言:javascript
复制
public class SomeClass
    {
    public SomeClass( string firstNonNullableValue, string secondNonNullableValue, string thirdNonNullableValue )
    {
        FirstNonNullableValue = firstNonNullableValue;
        SecondNonNullableValue = secondNonNullableValue;
        ThirdNonNullableValue = thirdNonNullableValue ;
    }

    public Guid Id { get; set; }

    public string FirstNonNullableValue{ get; set; }

    public string SecondNonNullableValue{ get; set; }

    public string ThirdNonNullableValue{ get; set; }

    public string? JustAString { get; set; }
//RangedValue is just a owned type with 2 ints
    public RangedValue? Value { get; set; }
    public RangedValue? Value2 { get; set; }
    public SomeEnum? SomeEnum{ get; set; }
    public IList<StringWrapper>? StringWrappers { get; set; }

    public string? SomeString { get; set; }
    public string? SomeString2 { get; set; }
}

编辑:包括构建日志

迁移

代码语言:javascript
复制
PS D:\Software\Visual Studio\Projects\Ecom\Ecom.Data> dotnet ef migrations add Tags -s ..\Ecom.API\ -o /migrations/Tags -v
Using project 'D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\Ecom.Data.csproj'.
Using startup project '..\Ecom.API\Ecom.API.csproj'.
Writing 'D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\obj\Ecom.Data.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Supremus\AppData\Local\Temp\tmpDD49.tmp /verbosity:quiet /nologo "D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\Ecom.Data.csproj"
Writing '..\Ecom.API\obj\Ecom.API.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Supremus\AppData\Local\Temp\tmpDFFA.tmp /verbosity:quiet /nologo ..\Ecom.API\Ecom.API.csproj
Build started...
dotnet build ..\Ecom.API\Ecom.API.csproj /verbosity:quiet /nologo

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.01
Build succeeded.
dotnet exec --depsfile "D:\Software\Visual Studio\Projects\Ecom\Ecom.API\bin\Debug\net5.0\Ecom.API.deps.json" --additionalprobingpath C:\Users\Supremus\.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --additionalprobingpath "C:\Program Files (x86)\Microsoft\Xamarin\NuGet" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig "D:\Software\Visual Studio\Projects\Ecom\Ecom.API\bin\Debug\net5.0\Ecom.API.runtimeconfig.json" C:\Users\Supremus\.dotnet\tools\.store\dotnet-ef\5.0.7\dotnet-ef\5.0.7\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations add Tags -o /migrations/Tags --assembly "D:\Software\Visual Studio\Projects\Ecom\Ecom.API\bin\Debug\net5.0\Ecom.Data.dll" --startup-assembly "D:\Software\Visual Studio\Projects\Ecom\Ecom.API\bin\Debug\net5.0\Ecom.API.dll" --project-dir "D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\\" --language C# --working-dir "D:\Software\Visual Studio\Projects\Ecom\Ecom.Data" --verbose --root-namespace Ecom.Data
Using assembly 'Ecom.Data'.
Using startup assembly 'Ecom.API'.
Using application base 'D:\Software\Visual Studio\Projects\Ecom\Ecom.API\bin\Debug\net5.0'.
Using working directory 'D:\Software\Visual Studio\Projects\Ecom\Ecom.API'.
Using root namespace 'Ecom.Data'.
Using project directory 'D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\'.
Remaining arguments: .
The Entity Framework tools version '5.0.7' is older than that of the runtime '5.0.9'. Update the tools for the latest features and bug fixes.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'Ecom.API'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Found DbContext 'EcomContext'.
Finding DbContext classes in the project...
Using context 'EcomContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.Sqlite'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.Sqlite'.
Finding design-time services referenced by assembly 'Ecom.API'...
Finding design-time services referenced by assembly 'Ecom.Data'...
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'Ecom.API'...
No design-time services were found.
Reusing namespace of type 'Init'.
An operation was scaffolded that may result in the loss of data. Please review the migration for accuracy.
Writing migration to 'D:\migrations\Tags\20210823160452_Tags.cs'.
Writing model snapshot to 'D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\Migrations\Product\EcomContextModelSnapshot.cs'.

更新

代码语言:javascript
复制
PS D:\Software\Visual Studio\Projects\Ecom\Ecom.Data> dotnet ef database update -s ..\Ecom.API\ -v
Using project 'D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\Ecom.Data.csproj'.
Using startup project '..\Ecom.API\Ecom.API.csproj'.
Writing 'D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\obj\Ecom.Data.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Supremus\AppData\Local\Temp\tmpFE02.tmp /verbosity:quiet /nologo "D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\Ecom.Data.csproj"
Writing '..\Ecom.API\obj\Ecom.API.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Supremus\AppData\Local\Temp\tmpC2.tmp /verbosity:quiet /nologo ..\Ecom.API\Ecom.API.csproj
Build started...
dotnet build ..\Ecom.API\Ecom.API.csproj /verbosity:quiet /nologo

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.15
Build succeeded.
dotnet exec --depsfile "D:\Software\Visual Studio\Projects\Ecom\Ecom.API\bin\Debug\net5.0\Ecom.API.deps.json" --additionalprobingpath C:\Users\Supremus\.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --additionalprobingpath "C:\Program Files (x86)\Microsoft\Xamarin\NuGet" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig "D:\Software\Visual Studio\Projects\Ecom\Ecom.API\bin\Debug\net5.0\Ecom.API.runtimeconfig.json" C:\Users\Supremus\.dotnet\tools\.store\dotnet-ef\5.0.7\dotnet-ef\5.0.7\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll database update --assembly "D:\Software\Visual Studio\Projects\Ecom\Ecom.API\bin\Debug\net5.0\Ecom.Data.dll" --startup-assembly "D:\Software\Visual Studio\Projects\Ecom\Ecom.API\bin\Debug\net5.0\Ecom.API.dll" --project-dir "D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\\" --language C# --working-dir "D:\Software\Visual Studio\Projects\Ecom\Ecom.Data" --verbose --root-namespace Ecom.Data
Using assembly 'Ecom.Data'.
Using startup assembly 'Ecom.API'.
Using application base 'D:\Software\Visual Studio\Projects\Ecom\Ecom.API\bin\Debug\net5.0'.
Using working directory 'D:\Software\Visual Studio\Projects\Ecom\Ecom.API'.
Using root namespace 'Ecom.Data'.
Using project directory 'D:\Software\Visual Studio\Projects\Ecom\Ecom.Data\'.
Remaining arguments: .
The Entity Framework tools version '5.0.7' is older than that of the runtime '5.0.9'. Update the tools for the latest features and bug fixes.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'Ecom.API'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Found DbContext 'EcomContext'.
Finding DbContext classes in the project...
Using context 'EcomContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.Sqlite'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.Sqlite'.
Finding design-time services referenced by assembly 'Ecom.API'...
Finding design-time services referenced by assembly 'Ecom.Data'...
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'Ecom.API'...
No design-time services were found.
Done.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-24 19:03:55

代码语言:javascript
复制
dotnet ef migrations add Init -o \Migrations\Init -s ..\<StartupLocation>

它缺少一个点,所以它输出到一个绝对路径,而不是一个相对路径.应该是

代码语言:javascript
复制
dotnet ef migrations add Init -o .\Migrations\Init -s ..\<StartupLocation>

注意输出文件夹中的点..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68884841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档