Npgsql.PostgresException Cannot login to target app


Type: C#Bot
Bot Version:
Browser / OS: Windows


Upon upgrading the application to the latest version of C# Bot, the target application cannot be logged into when run locally with docker. The error message is hard to read and therefore hard to debug but assumedly about the postgres database.

More information:

  • There are no protected regions, just a straight generated target app.
  • The model changed slightly but not significantly between generates
  • One table in the database was populated

Hi @samantha.swift!

Thank you for raising this to our attention. It sounds like a serious issue which I would assume is blocking you.

Are there any additional errors in your console, or is that error you took a screenshot of in there? Unfortunately the image cuts off some of the error so we can’t get a good read of it, so any extra information would be helpful. Could you please export it into a file so we can take a look, or maybe copy the error text out of the HTML? Likewise if there is anything odd coming up in your network tab, a copy of that may also be helpful.


(P.S. Welcome to the forum! :sunflower:)

Hi Tessa!

I know it is very hard to read the error, this has prevented me from doing some of my own troubleshooting unfortunately. I have tried to copy it etc but the popup won’t scroll or copy. I will try to inspect and see if I can extract it from the html. There are no other errors coming up in the console or build.

Thanks :smile:

Okay, if you can pull it out of the HTML that would be good, but if not we will make do with what we can see and go from there.

This is what I was able to get.

errorMessage.txt (6.7 KB)

Thanks Sam! I have forwarded this to the dev team, and they should get back to you soon.

1 Like

Hey Sam!

Reading the error, it looks like a column ‘PreferredTwoFactorMethod’ does not exist.

Two factor auth came out in ( )[ C#Bot Release - Release Notes / C#Bot - Codebots Community Forum]

I am wondering which version you are upgrading from, so that I can replicate this on my machine.

The first thing I would do is make a new migration with dotnet ef migrations add [NAME] in serverside/src and have a look inside the migration file that is produced. If the migration is empty, then there is trouble here. Otherwise if there is content inside the migration and it says anything about ‘PreferredTwoFactorMethod’ then applying the migration to the database could fix your problem.

Hi Tom!

The Migration is empty, but I have a data dump of the database will all the information I need to keep so maybe I will try to drop the database and redo. I believe I was upgrading from the previous version.

It is a database exception so it’s surely possible dropping the database could fix your problem. Otherwise I haven’t been able to reproduce the error when upgrading from the previous version. If you have no luck dropping the database, would you be able to send me a zip of the models folder (in the root dir of the target application)?

1 Like

I dropped the database, made another migration script and updated the database. Still getting the same error at login. I will send you a zip of the models folder as it won’t let me upload it.

So it turns out the issue was with the migrations. This issue was resolved by removing all the migrations and the model snapshot produced by entity framework in the migratrions folder and creating a new migrations using dotnet ef migrations add initial.

Npgsql.PostgresExceptions are database exceptions. In this case the error also mentioned that a column was missing in the database. This is a good sign that there is an issue with your database being out of sync with your codebase. The first port of call should be to check that your migrations are good and that your migrations have been run over your database.

1 Like

This sort of thing occurs when the database snapshot is out of sync with the actual state of the database. This sort of thing can happen when things like bad merges happen or if migrations were deleted by hand.

If you do need to delete a migration then run the command dotnet ef migrations remove to remove the latest migration. If you do not use this command then the DBContextModelSnapshot file can become out of sync and these sorts of issues can crop up.

1 Like