小编mmc*_*han的帖子

SQLAlchemy模型循环导入

我在同一个模块中有两个模型models.它们是1-1关系,并且已根据SQLAlchemy文档进行配置.

Vehicle.py

from models.AssetSetting import AssetSetting

class Vehicle(Base):
     __tablename__ = 'vehicles'

     vehicle_id = Column(Integer, primary_key=True)
     ...
     settings = relationship('AssetSetting', backref=backref('asset_settings'))
Run Code Online (Sandbox Code Playgroud)

AssetSetting.py

from models.Vehicle import Vehicle

class AssetSetting(Base):
     __tablename__ = 'asset_settings'

     asset_alert_setting_id = Column(Integer, primary_key=True, autoincrement=True)
     ...

     vehicle = relationship('vehicles', foreign_keys=Column(ForeignKey('vehicles.vehicle_id')))
Run Code Online (Sandbox Code Playgroud)

如果我使用字符串关系构建(即ForeignKey('vehicles.vehicle_id'))我得到错误:

sqlalchemy.exc.InvalidRequestError: 
When initializing mapper Mapper|AssetSetting|asset_settings, expression 'vehicles' failed to locate a name ("name 'vehicles' is not defined"). 
If this is a class name, consider adding this relationship() to the <class 'models.AssetSetting.AssetSetting'> class after …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy

13
推荐指数
2
解决办法
5518
查看次数

EF 5代码迁移错误:"数据库中已存在名为_____的对象"

进行EF5代码迁移,并且一直有一个奇怪的反复出现的问题,现在让我无法工作.试图运行update-database并收到此错误:

数据库中已经有一个名为"RequestStatus"的对象.

详细日志转储:

PM> update-database -v
Using StartUp project 'LicensingWorkflow'.
Using NuGet project 'LicensingWorkflow'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'LicensingWorkflow.Models.LicenseWorkflowContext' (DataSource: (localdb)\v11.0, Provider: System.Data.SqlClient, Origin: Convention).
Applying code-based migrations: [201311111934210_AddRequestStatusToContext].
Applying code-based migration: 201311111934210_AddRequestStatusToContext.
CREATE TABLE [dbo].[RequestStatus] (
    [Id] [bigint] NOT NULL IDENTITY,
    [Status] [nvarchar](max),
    CONSTRAINT [PK_dbo.RequestStatus] PRIMARY KEY ([Id])
)
System.Data.SqlClient.SqlException (0x80131904): There is already an object named 'RequestStatus' in the database.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException …
Run Code Online (Sandbox Code Playgroud)

c# database ef-code-first ef-migrations entity-framework-5

12
推荐指数
1
解决办法
1万
查看次数

模拟对象仍然打电话给服务

所以我正在为我们的MVC4应用程序编写测试,并且我正在专门测试Controller操作.正如我在标题中提到的,测试仍然命中服务(WCF)而不是返回测试数据.我有这个控制器:

public class FormController : Controller
{
    public SurveyServiceClient Service { get; set; }
    public SurveyDao Dao { get; set; }

    public FormController(SurveyServiceClient service = null, SurveyDao dao = null)
    {
        this.Service = service ?? new SurveyServiceClient();
        this.Dao = dao ?? new SurveyDao(Service);
    }

    //
    // GET: /Form/

    public ActionResult Index()
    {
        var formsList = new List<FormDataTransformContainer>();
        Dao.GetForms().ForEach(form => formsList.Add(form.ToContainer()));

        var model = new IndexViewModel(){forms = formsList};
        return View("Index", model);
    }
Run Code Online (Sandbox Code Playgroud)

它使用这个DAO对象:

public class SurveyDao
{
    private readonly SurveyServiceClient _service; …
Run Code Online (Sandbox Code Playgroud)

c# wcf unit-testing justmock asp.net-mvc-4

5
推荐指数
0
解决办法
483
查看次数

安装门卫:未初始化的常量错误

我正在尝试在全新的rails(4.0.2)安装上安装Doorkeeper.在我将gem添加到gemfile并安装之后,我尝试运行

rails generate doorkeeper:install
Run Code Online (Sandbox Code Playgroud)

并得到以下错误:

/Users/mam8cc/Projects/doorkeeper/config/application.rb:10:in `<module:Doorkeeper>': uninitialized constant Doorkeeper::Rails::Application (NameError)
    from /Users/mam8cc/Projects/doorkeeper/config/application.rb:9:in `<top (required)>'
    from /Users/mam8cc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.2/lib/rails/commands.rb:43:in `require'
    from /Users/mam8cc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.2/lib/rails/commands.rb:43:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'
Run Code Online (Sandbox Code Playgroud)

我的applications.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module Doorkeeper
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails doorkeeper

3
推荐指数
1
解决办法
910
查看次数