向表中添加迁移时,该字段是重复的(但以 结尾1
):
CreateTable(
"public.t_users",
c => new
{
id = c.Int(nullable: false, identity: true),
login = c.String(),
password = c.String(),
name = c.String(),
role_id = c.Int(nullable: false),
role_id1 = c.Int(),
})
.PrimaryKey(t => t.id)
.ForeignKey("public.t_roles", t => t.role_id1)
.Index(t => t.role_id1);
虽然在数据库中它是一个:
-- Table: public.t_users
-- DROP TABLE public.t_users;
CREATE TABLE public.t_users
(
name character varying(100) COLLATE pg_catalog."default" NOT NULL,
login character varying(100) COLLATE pg_catalog."default" NOT NULL,
password character varying(100) COLLATE pg_catalog."default" NOT NULL,
role_id integer NOT NULL,
id integer NOT NULL DEFAULT nextval('t_users_id_seq'::regclass)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public.t_users
OWNER to psp;
如果它只在迁移期间会很好......但是当保存到数据库时也会弹出这个字段......并且自然会发生错误Entity
:
BaseMessage = "column \"role_id1\" of relation \"t_users\" does not exist"
模型:
namespace Loyalty.DAL.Models.Authorize
{
[Table("t_users", Schema = "public")]
public class User
{
[Key]
public int? id { get; set; }
public string login { get; set; }
public string password { get; set; }
public string name { get; set; }
public int role_id { get; set; }
public virtual Role role { get; set; }
}
}
请解释“如何”,以及他为什么(Entity
)添加此字段?
必须明确指出,该场是一个外层空间。