Linux上的Asp.net核心 - dotnet ef数据库更新失败,版本错误

时间:2016-12-07 15:13:18

标签: asp.net linux sqlite asp.net-core entity-framework-core

只需按照https://www.microsoft.com/net/core#linuxubuntuhttps://docs.microsoft.com/en-us/aspnet/core/getting-started

上的安装说明操作即可

到目前为止,一切都很好,除非在http://localhost:5000/Account/Register下创建新用户时失败

  

SQLite错误'没有这样的表:AspNetUsers'

SQLite Error  'no such table: AspNetUsers'

尝试使用dotnet ef database update创建表结构,但失败并出现版本错误。

enter image description here

现在我迷失了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 core - no such table: AspNetUsers看似相似,但它是Windows。

enter image description here

如何更新project.json以获取初始ASP.net核心模板并保存到SQlite?或者在Ubuntu上关于SQlite还有什么遗漏?版本libsqlite3-0:amd64中的3.14.1-1build1已安装...

2 个答案:

答案 0 :(得分:0)

当我在MAC上开发并部署到Debian时,我遇到了同样的问题。我最终将数据库文件从我的开发机器复制到生产服务器。如果检查从publish命令生成的数据库文件,则该文件为空。希望这能帮到你!

答案 1 :(得分:0)

使用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。