Linux上的Asp.net核心 - dotnet ef數據庫更新失敗,版本錯誤

asp.net asp.net-core entity-framework-core linux sqlite

只需按照https://www.microsoft.com/net/core#linuxubuntuhttps://docs.microsoft.com/en-us/aspnet/core/getting-started上的安裝說明進行操作即可

到目前為止一切都很好,除非在http:// localhost:5000 / Account / Register下創建新用戶時失敗

SQLite錯誤'沒有這樣的表:AspNetUsers'

SQLite錯誤'沒有這樣的表:AspNetUsers'

嘗試使用dotnet ef database update來創建表結構,但它失敗並出現版本錯誤。

在此處輸入圖像描述

現在我迷失了project.json中的所有不同版本,何時使用1.1.0和什麼時候1.0.0 ,什麼時候應該是preview1-final preview2-final preview3-final或者甚至更好的preview2-update1

dotnet new -t web之後開箱即用的project.json

{
  "userSecretsId": "aspnet-WebApplication-0799fe3e-6eaf-4c5f-b40e-7c6bfd5dfa9a",

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.1.0-preview1-001153-00",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-update1",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview2-update1",
      "type": "build"
    }
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    },
    "Microsoft.Extensions.SecretManager.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },

  "tooling": {
    "defaultNamespace": "WebApplication"
  }
}

Asp.net核心 - 沒有這樣的表:AspNetUsers和似乎相似,但它是Windows。

在此處輸入圖像描述

如何更新project.json以獲取初始ASP.net核心模板並保存到SQlite?或者在Ubuntu上關於SQlite還有什麼遺漏? libsqlite3-0:amd64安裝了版本3.14.1-1build1 libsqlite3-0:amd64 ...

一般承認的答案

使用github的最新位( 1.0.0-rc4-004777 )和github上的一些幫助( EF Core Tools Bug Bash#7358 )我得到了一個解決方案

wget https://dotnetcli.blob.core.windows.net/dotnet/Sdk/rel-1.0.0/dotnet-dev-ubuntu.16.04-x64.latest.tar.gz
sudo mkdir /opt/dotnet
sudo tar zxvf dotnet-dev-ubuntu.16.04-x64.latest.tar.gz -C /opt/dotnet
sudo ln -s /opt/dotnet/dotnet /usr/local/bin
mkdir testweb
cd testweb
dotnet new mvc --auth Individual
dotnet restore

編輯.csproj並添加

<ItemGroup>
  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
                          Version="1.0.0-msbuild3-final" />
</ItemGroup>

保存.csproj後,您將能夠創建數據庫,模板將運行正常。

dotnet restore
dotnet ef database update
dotnet run

有了上述所有功能,現在可以在Linux下運行模板並創建用戶並登錄http:// localhost:5000 / Account / Register ,並將EntityFrameworkCore存儲到sqlite。


熱門答案

當我在MAC上開發並部署到Debian時,我遇到了同樣的問題。我最終將數據庫文件從我的開發機器複製到生產服務器。如果檢查從publish命令生成的數據庫文件,則該文件為空。希望這對你有所幫助!



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow