Error Number:2705,State:4,Class:16
Column names in each table must be unique. Column name 'IsActive' in table 'dbo.Enrollments' is specified more than once.
l try to update- databas and l got error below
[EDIT]
Removed all the view and ASP.NET code as it has nothing to do with the error.
the models as
namespace StudentEnrollment.Models
{
public class Course
{
[Display(Name = "Course ID")]
public virtual int Id { get; set; }
[Display(Name = "Course Title")]
[Required(ErrorMessage = "Enter Title for course")]
[MaxLength(50, ErrorMessage = "Allowable max is 150")]
public virtual string Title { get; set; }
[Display(Name = "Description")]
public virtual string Description { get; set; }
[Display(Name = "Number of Credits")]
[Required(ErrorMessage = "Enter credits for course")]
[RegularExpression("^[1-4]{1}$", ErrorMessage = "Enter value either 1,2 or 3,4")]
public virtual string Credits { get; set; }
}
}
namespace StudentEnrollment.Models
{
public class Enrollment
{
public virtual int Id { get; set; }
[Display(Name = "Student ID")]
public virtual int StudentId { get; set; }
public Student Student { get; set; }
[Display(Name = "Course ID")]
public virtual int CourseId { get; set; }
public Course Course { get; set; }
[Display(Name = "Grade")]
[RegularExpression("^[A-F]{1}$", ErrorMessage = "Enter value A , B, C, D, E, F")]
public virtual string Grade { get; set; }
public bool IsActive { get; set; }
[Display(Name = "Assigned Campus")]
[Required(ErrorMessage = "Enter value for campus")]
public virtual string AssignedCampus { get; set; }
[Display(Name = "Enrolled in Semester")]
[Required(ErrorMessage = "Enter enrollment semester")]
public virtual string EnrollmentSemester { get; set; }
[Display(Name = "Enrollment Year")]
[Required(ErrorMessage = "Enter value for Enrollment Year ")]
[Range(2018,2020, ErrorMessage = "Enter value greater than 2018")]
public virtual int EnrollmentYear { get; set; }
public virtual String Notes { get; set; }
}
}
namespace StudentEnrollment.Models
{
public class Student
{
[Display(Name = "Student ID")]
public virtual int Id { get; set; }
[Display(Name = "Last Name")]
[Required(ErrorMessage = "Enter value for Last Name")]
[MaxLength(50, ErrorMessage = "Allowable max is 50")]
public virtual string LastName { get; set; }
[Display(Name = "First Name")]
[Required(ErrorMessage = "Enter value for First Name")]
[MaxLength(50, ErrorMessage = "Allowable max length is 50")]
public virtual string FirstName { get; set; }
}
}
there is still AN error
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) ClientConnectionId:5f388873-4c88-4dfa-96ec-5412a7dfdcce Error Number:2705, State:4,Class:16 olumn names in each table must be unique. Column name IsActive in table dbo. Enrollments is specified more than once. PM>
Is there is soltion as query inside the table to solve the issues????
this is the enrollemnt query
CREATE TABLE [dbo].[Enrollments] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[StudentId] INT NOT NULL,
[CourseId] INT NOT NULL,
[Grade] NVARCHAR (MAX) NULL,
[IsActive] BIT NULL,
[AssignedCampus] VARCHAR (MAX) NULL,
[EnrollmentSemester] VARCHAR (MAX) NULL,
[EnrollmentYear] INT NULL,
CONSTRAINT [PK_dbo.Enrollments] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_dbo.Enrollments_dbo.Courses_CourseId] FOREIGN KEY ([CourseId]) REFERENCES [dbo].[Courses] ([Id]) ON DELETE CASCADE,
CONSTRAINT [FK_dbo.Enrollments_dbo.Students_StudentId] FOREIGN KEY ([StudentId]) REFERENCES [dbo].[Students] ([Id]) ON DELETE CASCADE
);
GO
CREATE NONCLUSTERED INDEX [IX_StudentId]
ON [dbo].[Enrollments]([StudentId] ASC);
GO
CREATE NONCLUSTERED INDEX [IX_CourseId]
ON [dbo].[Enrollments]([CourseId] ASC);
Show transcribed image text
What I have tried:
l did try update-database using visual studio 2017 but it keep generating the same error Is active is more than one and also Notes column is not valid
this the error message
Error Number:2705,State:4,Class:16
Column names in each table must be unique. Column name 'IsActive' in table 'dbo.Enrollments' is specified more than once.
PM>