Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaffold failing #405

Closed
adopilot opened this issue May 15, 2018 · 5 comments
Closed

Scaffold failing #405

adopilot opened this issue May 15, 2018 · 5 comments

Comments

@adopilot
Copy link

My apologies if this is already open.

I am trying to Scaffold this table

-- Table: public.topics

-- DROP TABLE public.topics;

CREATE TABLE public.topics
(
    id integer NOT NULL ,
    title character varying(255) COLLATE pg_catalog."default" NOT NULL,
    last_posted_at timestamp without time zone,
    created_at timestamp without time zone NOT NULL,
    updated_at timestamp without time zone NOT NULL,
    views integer NOT NULL DEFAULT 0,
    posts_count integer NOT NULL DEFAULT 0,
    user_id integer,
    last_post_user_id integer NOT NULL,
    reply_count integer NOT NULL DEFAULT 0,
    featured_user1_id integer,
    featured_user2_id integer,
    featured_user3_id integer,
    avg_time integer,
    deleted_at timestamp without time zone,
    highest_post_number integer NOT NULL DEFAULT 0,
    image_url character varying(255) COLLATE pg_catalog."default",
    like_count integer NOT NULL DEFAULT 0,
    incoming_link_count integer NOT NULL DEFAULT 0,
    category_id integer,
    visible boolean NOT NULL DEFAULT true,
    moderator_posts_count integer NOT NULL DEFAULT 0,
    closed boolean NOT NULL DEFAULT false,
    archived boolean NOT NULL DEFAULT false,
    bumped_at timestamp without time zone NOT NULL,
    has_summary boolean NOT NULL DEFAULT false,
    vote_count integer NOT NULL DEFAULT 0,
    archetype character varying(255) COLLATE pg_catalog."default" NOT NULL DEFAULT 'regular'::character varying,
    featured_user4_id integer,
    notify_moderators_count integer NOT NULL DEFAULT 0,
    spam_count integer NOT NULL DEFAULT 0,
    pinned_at timestamp without time zone,
    score double precision,
    percent_rank double precision NOT NULL DEFAULT 1.0,
    subtype character varying(255) COLLATE pg_catalog."default",
    slug character varying(255) COLLATE pg_catalog."default",
    deleted_by_id integer,
    participant_count integer DEFAULT 1,
    word_count integer,
    excerpt character varying(1000) COLLATE pg_catalog."default",
    pinned_globally boolean NOT NULL DEFAULT false,
    pinned_until timestamp without time zone,
    fancy_title character varying(400) COLLATE pg_catalog."default",
    highest_staff_post_number integer NOT NULL DEFAULT 0,
    featured_link character varying COLLATE pg_catalog."default",
    CONSTRAINT forum_threads_pkey PRIMARY KEY (id),
    CONSTRAINT has_category_id CHECK (category_id IS NOT NULL OR archetype::text <> 'regular'::text),
    CONSTRAINT pm_has_no_category CHECK (category_id IS NULL OR archetype::text <> 'private_message'::text)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE public.topics
    OWNER to discourse;
COMMENT ON TABLE public.topics
    IS 'To query public topics only: SELECT ... FROM topics t LEFT INNER JOIN categories c ON (t.category_id = c.id AND c.read_restricted = false)';

-- Index: idx_topics_front_page

-- DROP INDEX public.idx_topics_front_page;

CREATE INDEX idx_topics_front_page
    ON public.topics USING btree
    (deleted_at, visible, archetype COLLATE pg_catalog."default", category_id, id)
    TABLESPACE pg_default;

-- Index: idx_topics_user_id_deleted_at

-- DROP INDEX public.idx_topics_user_id_deleted_at;

CREATE INDEX idx_topics_user_id_deleted_at
    ON public.topics USING btree
    (user_id)
    TABLESPACE pg_default    WHERE deleted_at IS NULL
;

-- Index: idxtopicslug

-- DROP INDEX public.idxtopicslug;

CREATE INDEX idxtopicslug
    ON public.topics USING btree
    (slug COLLATE pg_catalog."default")
    TABLESPACE pg_default    WHERE deleted_at IS NULL AND slug IS NOT NULL
;

-- Index: index_topics_on_bumped_at

-- DROP INDEX public.index_topics_on_bumped_at;

CREATE INDEX index_topics_on_bumped_at
    ON public.topics USING btree
    (bumped_at DESC)
    TABLESPACE pg_default;

-- Index: index_topics_on_created_at_and_visible

-- DROP INDEX public.index_topics_on_created_at_and_visible;

CREATE INDEX index_topics_on_created_at_and_visible
    ON public.topics USING btree
    (created_at, visible)
    TABLESPACE pg_default    WHERE deleted_at IS NULL AND archetype::text <> 'private_message'::text
;

-- Index: index_topics_on_id_and_deleted_at

-- DROP INDEX public.index_topics_on_id_and_deleted_at;

CREATE INDEX index_topics_on_id_and_deleted_at
    ON public.topics USING btree
    (id, deleted_at)
    TABLESPACE pg_default;

-- Index: index_topics_on_lower_title

-- DROP INDEX public.index_topics_on_lower_title;

CREATE INDEX index_topics_on_lower_title
    ON public.topics USING btree
    (lower(title::text) COLLATE pg_catalog."default")
    TABLESPACE pg_default;

-- Index: index_topics_on_pinned_at

-- DROP INDEX public.index_topics_on_pinned_at;

CREATE INDEX index_topics_on_pinned_at
    ON public.topics USING btree
    (pinned_at)
    TABLESPACE pg_default    WHERE pinned_at IS NOT NULL
;

-- Index: index_topics_on_pinned_globally

-- DROP INDEX public.index_topics_on_pinned_globally;

CREATE INDEX index_topics_on_pinned_globally
    ON public.topics USING btree
    (pinned_globally)
    TABLESPACE pg_default    WHERE pinned_globally
;

When I run

Scaffold-DbContext "Host=server;Database=test1;Username=aaa ;Password=aa" Npgsql.EntityFrameworkCore.PostgreSQL

I get

The collection argument 'propertyNames' must contain at least one element.

Full trace of output is

The column 'public.topics.visible' would normally be mapped to a non-nullable bool property, but it has a default constraint. Such a column is mapped to a nullable bool property to allow a difference between setting the property to false and invoking the default constraint. See https://go.microsoft.com/fwlink/?linkid=851278 for details.
The column 'public.topics.closed' would normally be mapped to a non-nullable bool property, but it has a default constraint. Such a column is mapped to a nullable bool property to allow a difference between setting the property to false and invoking the default constraint. See https://go.microsoft.com/fwlink/?linkid=851278 for details.
The column 'public.topics.archived' would normally be mapped to a non-nullable bool property, but it has a default constraint. Such a column is mapped to a nullable bool property to allow a difference between setting the property to false and invoking the default constraint. See https://go.microsoft.com/fwlink/?linkid=851278 for details.
The column 'public.topics.has_summary' would normally be mapped to a non-nullable bool property, but it has a default constraint. Such a column is mapped to a nullable bool property to allow a difference between setting the property to false and invoking the default constraint. See https://go.microsoft.com/fwlink/?linkid=851278 for details.
The column 'public.topics.pinned_globally' would normally be mapped to a non-nullable bool property, but it has a default constraint. Such a column is mapped to a nullable bool property to allow a difference between setting the property to false and invoking the default constraint. See https://go.microsoft.com/fwlink/?linkid=851278 for details.
System.ArgumentException: The collection argument 'propertyNames' must contain at least one element.
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty[T](IReadOnlyList`1 value, String parameterName)
   at Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder.HasIndex(String[] propertyNames)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitIndex(EntityTypeBuilder builder, DatabaseIndex index)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitIndexes(EntityTypeBuilder builder, ICollection`1 indexes)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTable(ModelBuilder modelBuilder, DatabaseTable table)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTables(ModelBuilder modelBuilder, ICollection`1 tables)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitDatabaseModel(ModelBuilder modelBuilder, DatabaseModel databaseModel)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.CreateFromDatabaseModel(DatabaseModel databaseModel, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ModelScaffolder.Generate(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String projectPath, String outputPath, String rootNamespace, String contextName, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The collection argument 'propertyNames' must contain at least one element.
@roji
Copy link
Member

roji commented May 15, 2018

What version of EF Core are you using (both Npgsql and Microsoft packages)?

@adopilot
Copy link
Author

Npgsql.EntityFrameworkCore.PostgreSQL version 2.0.2
EntityFramework version 6.2.0
Microsoft.EntityFrameworkCore.SqlServer version 2.0.3
Microsoft.EntityFrameworkCore.Tools version 2.0.3

App is .net core 2.0

image

@TheBaradhur
Copy link

TheBaradhur commented May 23, 2018

@roji I'm having exactly the same problem. Please remove the waiting for answer tag.

Microsoft.EntityFrameworkCore version 2.0.3
Microsoft.EntityFrameworkCore.Tools version 2.0.3
Npgsql.EntityFrameworkCore.PostgreSQL version 2.0.2

App is .net core 2.0

DB Scheme is creating Indexes just like OP. Can't copy paste for reasons, but here is a little piece.

CREATE INDEX aspnet_users_email_index
  ON public.aspnet_users
  USING btree
  (email COLLATE pg_catalog."default");

Running the following:
dotnet ef dbcontext scaffold "Server=localhost;Port=1234;Database=blah;Username=xxx;Password=xxx" Npgsql.EntityFrameworkCore.PostgreSQL -t aspnet_users -d

Getting the following error:
The collection argument 'propertyNames' must contain at least one element.

System.ArgumentException: The collection argument 'propertyNames' must contain at least one element.
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty[T](IReadOnlyList`1 value, String parameterName)
   at Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder.HasIndex(String[] propertyNames)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitIndex(EntityTypeBuilder builder, DatabaseIndex index)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitIndexes(EntityTypeBuilder builder, ICollection`1 indexes)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTable(ModelBuilder modelBuilder, DatabaseTable table)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTables(ModelBuilder modelBuilder, ICollection`1 tables)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitDatabaseModel(ModelBuilder modelBuilder, DatabaseModel databaseModel)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.CreateFromDatabaseModel(DatabaseModel databaseModel, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ModelScaffolder.Generate(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String projectPath, String outputPath, String rootNamespace, String contextName, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The collection argument 'propertyNames' must contain at least one element.

I can't find a solution over the internet so help would be much appreciated.

@roji
Copy link
Member

roji commented May 23, 2018

@adopilot EF6 issues should be opened in https://github.com/npgsql/EntityFramework6.Npgsql, this repo is for EF Core.

@roji
Copy link
Member

roji commented May 23, 2018

This looks like a duplicate of #228, which is caused by two indices existing on the same column, see there for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants