Repository navigation
Description
Right now I'm unable to scaffold a model for an existing postgres database. I do get the error message Column is null.
I set up two demo projects which I used to reproduce this effect even with a completely new project.
ScaffoldTestNET
ScaffoldTestDnx
As you can see one is using dnx and the other is using .NET 4.6.1
The error message is the same for both projects. A dump of the database I have been using for this can be found here: https://gist.github.com/eBerdnA/e5f790dc205e6dc07818
Following the stacktrace when I run dnx ef dbcontext scaffold "Host=localhost;Username=postgres;Password=test1234;Database=Homepage" EntityFramework7.Npgsql --outputDir Models in ScaffoldTestDnx
System.InvalidCastException: Column is null
at Npgsql.BackendMessages.DataRowMessage.CheckNotNull()
at Npgsql.NpgsqlDataReader.ReadColumnWithoutCache[T](Int32 ordinal)
at Npgsql.NpgsqlDataReader.GetString(Int32 ordinal)
at Microsoft.Data.Entity.Scaffolding.NpgsqlDatabaseModelFactory.GetColumns()
at Microsoft.Data.Entity.Scaffolding.NpgsqlDatabaseModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.Data.Entity.Scaffolding.RelationalScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.Data.Entity.Scaffolding.NpgsqlScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
at Microsoft.Data.Entity.Scaffolding.Internal.ReverseEngineeringGenerator.GetMetadataModel(ReverseEngineeringConfiguration configuration)
at Microsoft.Data.Entity.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
at Microsoft.Data.Entity.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, List`1 schemas, List`1 tables, Boolean useDataAnnotations, CancellationToken cancellationToken)
at Microsoft.Data.Entity.Commands.Program.Executor.<>c__DisplayClass11_0.<<ReverseEngineerAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Data.Entity.Commands.Program.Executor.<ExecuteAsync>d__13.MoveNext()
Column is null
If any further information or help is needed just let me know.
Activity
eBerdnA commentedon Dec 27, 2015
I'm very sorry for opening this issue. But somehow my local test database seems to be "corrupted". After creating a new local db from my gist I noticed that scaffolding works without any issue.
Then I created a full backup including data and restored it as a new database. Then I was also able to scaffold.
Therefore somehow my local db seems to be "corrupted" even though I don't know where exactly.
Due to the fact that I can't even reproduce this effect on my machine with a full backup of the db I will close this issue.
eBerdnA commentedon Dec 29, 2015
I think I found a way to reproduce this effect. The following steps should lead to the problem.
1 - First of all create two tables.
Scaffolding should be possible now.
2 - Add a new column to table Article and a constraint
Scaffolding should still be possible.
3 - Remove the added constraint and the column from table Article.
Now scaffolding should fail with
Column is null.roji commentedon Dec 29, 2015
This happens here, will investigate.
[-]Can't scaffold database[/-][+]Scaffolding fails because of dropped column traces[/+]roji commentedon Dec 29, 2015
@eBerdnA fixed this, thanks for the time spent isolating it!
PostgreSQL's pg_attribute table, which the scaffolding process consults, contains traces of dropped columns which were causing errors. This is why the error was only reproducible after dropping columns.
I am in the process of making the work again on our build server, at which point unstable nugets with this fix will automatically appear in our unstable myget feed. This should happen in the next few days.
Thanks again, and continue reporting any other issues you find!
[RevEng] Ignore dropped columns
adopilot commentedon May 26, 2017
@roji Unfortunately Looks like we again have issues with Scaffolding DBs which changed structure.
In VS2016 CE whit packages
When I try to
Scaffold-DbContext "Host=forum.robot.ba;Database=XXXX;Username=XXX;Password=XXX" Npgsql.EntityFrameworkCore.PostgreSQL -o Data\Forum -Context ForumDbContextI get exception
When I do dump Only schema and restore it to other new database Scaffolding whent only whit warnings.
But I do get context and looks to me good code whic compile and run.
I rely do not what changes occurs on my original pg database because I do not own it and Do not deply it.
roji commentedon May 26, 2017
@adopilot this issue has been fixed, but version 1.1.1 hasn't been released yet. I hope this will happen in the next week or two, at which point the problem should go away.