✅ ef not being able to update database migrations

I've been trying to learn aspnet and done just the basics of it. But when using dotnet ef database update, after adding a migration, the same SQLite Error 1: 'no such table: __EFMigrationsHistory'. happens, eventhough that table is being created (or was supposed to be created) on the initial migration. I only have 1 service and 1 model now, so that error makes no sense for me, as it's the only language that happened for me.
39 Replies
Sun「無用」
Sun「無用」OP2y ago
The database was fully created by ef and it'll be only used by ef
Head0nF1re
Head0nF1re2y ago
@sunpoke04 How did you create the database?
Sun「無用」
Sun「無用」OP2y ago
. I didn't even touch the db.
Head0nF1re
Head0nF1re2y ago
This example from the offical docs uses SQLite: - https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app?tabs=netcore-cli Compare, see if you miss something
Sun「無用」
Sun「無用」OP2y ago
they used the same commands as me.
Head0nF1re
Head0nF1re2y ago
Show the code for the Database Context
Sun「無用」
Sun「無用」OP2y ago
using ChatboxApi.Api.Features.User;
using Microsoft.EntityFrameworkCore;

namespace ChatboxApi.Api.Common.Context;

public class ApplicationDbContext : DbContext
{
public DbSet<User>? Users { get; set; }

public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
}
using ChatboxApi.Api.Features.User;
using Microsoft.EntityFrameworkCore;

namespace ChatboxApi.Api.Common.Context;

public class ApplicationDbContext : DbContext
{
public DbSet<User>? Users { get; set; }

public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
}
I haven't even put anything inside that set, just trying to create it
Head0nF1re
Head0nF1re2y ago
Do you think it's the same as what's shown in their example?
Sun「無用」
Sun「無用」OP2y ago
yes. Since it's being setup in the Program.cs
Head0nF1re
Head0nF1re2y ago
Show it...
Sun「無用」
Sun「無用」OP2y ago
?
Head0nF1re
Head0nF1re2y ago
What's in Program.cs
Sun「無用」
Sun「無用」OP2y ago
builder.Services.AddDbContext<ApplicationDbContext>(opt => opt.UseSqlite(builder.Configuration.GetConnectionString("SqliteConnection"))); again, I'm not an idiot. I am configuring it.
Head0nF1re
Head0nF1re2y ago
public BloggingContext()
{
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
DbPath = System.IO.Path.Join(path, "blogging.db");
}

// The following configures EF to create a Sqlite database file in the
// special "local" folder for your platform.
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
}
public BloggingContext()
{
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
DbPath = System.IO.Path.Join(path, "blogging.db");
}

// The following configures EF to create a Sqlite database file in the
// special "local" folder for your platform.
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={DbPath}");
}
Sun「無用」
Sun「無用」OP2y ago
it's the same thing, written on a different way
Head0nF1re
Head0nF1re2y ago
Do you have the path defined as an absolute path?
Sun「無用」
Sun「無用」OP2y ago
the db path is being defined in the appsettings.json. I'm not gonna show that.
Sun「無用」
Sun「無用」OP2y ago
In that, the db is being created, with the tables. And the migrations are being applied. My migrations are never being updated.
Head0nF1re
Head0nF1re2y ago
You said your first migration applied, no?
Sun「無用」
Sun「無用」OP2y ago
I could create a migration, I can't update to db. that's the title of this channel
Head0nF1re
Head0nF1re2y ago
Nvm, that happens on the initial migration / first update?
Sun「無用」
Sun「無用」OP2y ago
> dotnet ef database update
... Some stuff b4 that
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'no such table: __EFMigrationsHistory'.
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteCommand.PrepareAndEnumerateStatements(Stopwatch timer)+MoveNext()
at Microsoft.Data.Sqlite.SqliteCommand.GetStatements(Stopwatch timer)+MoveNext()
at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
SQLite Error 1: 'no such table: __EFMigrationsHistory'.
> dotnet ef database update
... Some stuff b4 that
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'no such table: __EFMigrationsHistory'.
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteCommand.PrepareAndEnumerateStatements(Stopwatch timer)+MoveNext()
at Microsoft.Data.Sqlite.SqliteCommand.GetStatements(Stopwatch timer)+MoveNext()
at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
SQLite Error 1: 'no such table: __EFMigrationsHistory'.
Since you don't seem to understand it
Head0nF1re
Head0nF1re2y ago
I did understand, I'm asking if that happens the first time you use "dotnet ef database update" or the second time
Sun「無用」
Sun「無用」OP2y ago
every time... doesn't matter how many times I run it, it does the same thing
Head0nF1re
Head0nF1re2y ago
Ok, you said you have your path in appsetting.json. Is it an absolute or relative path?
Sun「無用」
Sun「無用」OP2y ago
something like Data Source=somedblikethat.db
Head0nF1re
Head0nF1re2y ago
It's relative then. That's your problem I think Try with a full/absolute path
Sun「無用」
Sun「無用」OP2y ago
it still should do whatever it does
Head0nF1re
Head0nF1re2y ago
Anything?
Sun「無用」
Sun「無用」OP2y ago
nothing changed yes, I dropped the old db before doing another update.
Head0nF1re
Head0nF1re2y ago
It's a new app? Will try here
Sun「無用」
Sun「無用」OP2y ago
?
Head0nF1re
Head0nF1re2y ago
Version 6? I will try to create a new app here Dotnet version 6? 7?
Sun「無用」
Sun「無用」OP2y ago
7
Head0nF1re
Head0nF1re2y ago
I followed the example and had no problem creating it Just had problem finding the db lol
Sun「無用」
Sun「無用」OP2y ago
? then what would be the problem? because everything looks like it should work but it doesn't
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Sun「無用」
Sun「無用」OP2y ago
no, the command is still not working
Want results from more Discord servers?
Add your server