C
C#3mo ago
UntoldTitan

✅ EFCore 8 MySQL - Table doesn't exist, but it does?

I'm trying to use EFCore to integrate with an existing database, but apparently the table doesn't exist, even though it clearly does. I'm manually writing the class for Products since EFCore didn't automatically generate it. What the heck is going on here?
No description
No description
35 Replies
Jimmacle
Jimmacle3mo ago
instead of manually writing the dbcontext, use scaffolding
UntoldTitan
UntoldTitanOP3mo ago
namespace NordicDBDeserializer.NordicDB
{
[Table("nordicmarksman_Products")]
public class Product
{
[Key]
public int ProductID { get; set; }
public int ProducType { get; set; }
public string SKU { get; set; }
public string ModelNumber { get; set; }
public int DefaultBrandID { get; set; }
public string ProductName { get; set; }
}
}
namespace NordicDBDeserializer.NordicDB
{
[Table("nordicmarksman_Products")]
public class Product
{
[Key]
public int ProductID { get; set; }
public int ProducType { get; set; }
public string SKU { get; set; }
public string ModelNumber { get; set; }
public int DefaultBrandID { get; set; }
public string ProductName { get; set; }
}
}
I can't, DB has to be first
Jimmacle
Jimmacle3mo ago
that's what scaffolding is
Jimmacle
Jimmacle3mo ago
Reverse Engineering - EF Core
Reverse engineering a model from an existing database using Entity Framework Core
Jimmacle
Jimmacle3mo ago
it generates classes from your existing database
UntoldTitan
UntoldTitanOP3mo ago
Ah
Jimmacle
Jimmacle3mo ago
then you don't risk making errors manually translating the schema
UntoldTitan
UntoldTitanOP3mo ago
I've done that already, thats how I got some of the classes, it didn't pick up all the tables
UntoldTitan
UntoldTitanOP3mo ago
No description
UntoldTitan
UntoldTitanOP3mo ago
+-----------------------------------------+
| Tables_in_nordic |
+-----------------------------------------+
| nordicmarksman_BrandLinks |
| nordicmarksman_Brands |
| nordicmarksman_Brands_Lang |
| nordicmarksman_CartPromos |
| nordicmarksman_CatGroups |
| nordicmarksman_CatGroups_Lang |
| nordicmarksman_CatLinks |
| nordicmarksman_Categories |
| nordicmarksman_Categories_Lang |
| nordicmarksman_CouponLinks |
| nordicmarksman_Currency |
| nordicmarksman_CustomerGroupRules |
| nordicmarksman_CustomerGroupVisibility |
| nordicmarksman_CustomerGroups |
| nordicmarksman_CustomerMessages |
| nordicmarksman_Customers |
| nordicmarksman_CustomersAffiliates |
| nordicmarksman_Events |
| nordicmarksman_Languages |
| nordicmarksman_Modules |
| nordicmarksman_Pages |
| nordicmarksman_PagesBlog |
| nordicmarksman_PagesGallery |
| nordicmarksman_PagesLocations |
| nordicmarksman_Pages_Lang |
| nordicmarksman_ProductCoupons |
| nordicmarksman_ProductDiscounts |
| nordicmarksman_ProductImages |
| nordicmarksman_ProductImages_Lang |
| nordicmarksman_ProductOptionLinks |
| nordicmarksman_ProductOptionNames |
| nordicmarksman_ProductOptionNames_Lang |
| nordicmarksman_ProductOptionValues |
| nordicmarksman_ProductOptionValues_Lang |
| nordicmarksman_ProductTabLinks |
| nordicmarksman_ProductTabs |
| nordicmarksman_ProductTabs_Lang |
| nordicmarksman_ProductUpsell |
| nordicmarksman_Products |
| nordicmarksman_Products_Lang |
| nordicmarksman_Purchases |
| nordicmarksman_PurchasesAffiliates |
| nordicmarksman_PurchasesCustomers |
| nordicmarksman_PurchasesData |
| nordicmarksman_PurchasesExtras |
| nordicmarksman_PurchasesGifts |
| nordicmarksman_PurchasesInvoices |
| nordicmarksman_PurchasesProgress |
| nordicmarksman_Regions |
| nordicmarksman_Reviews |
| nordicmarksman_Session |
| nordicmarksman_Settings |
| nordicmarksman_Shipping |
| nordicmarksman_ShippingMethods |
| nordicmarksman_ShippingPostalZip |
| nordicmarksman_ShippingZones |
| nordicmarksman_SubscriptionProducts |
| nordicmarksman_SubscriptionProfiles |
| nordicmarksman_TasksEmail |
| nordicmarksman_TasksQueue |
| nordicmarksman_TaxClasses |
| nordicmarksman_Taxes |
| nordicmarksman_URI |
| nordicmarksman_Users |
+-----------------------------------------+
+-----------------------------------------+
| Tables_in_nordic |
+-----------------------------------------+
| nordicmarksman_BrandLinks |
| nordicmarksman_Brands |
| nordicmarksman_Brands_Lang |
| nordicmarksman_CartPromos |
| nordicmarksman_CatGroups |
| nordicmarksman_CatGroups_Lang |
| nordicmarksman_CatLinks |
| nordicmarksman_Categories |
| nordicmarksman_Categories_Lang |
| nordicmarksman_CouponLinks |
| nordicmarksman_Currency |
| nordicmarksman_CustomerGroupRules |
| nordicmarksman_CustomerGroupVisibility |
| nordicmarksman_CustomerGroups |
| nordicmarksman_CustomerMessages |
| nordicmarksman_Customers |
| nordicmarksman_CustomersAffiliates |
| nordicmarksman_Events |
| nordicmarksman_Languages |
| nordicmarksman_Modules |
| nordicmarksman_Pages |
| nordicmarksman_PagesBlog |
| nordicmarksman_PagesGallery |
| nordicmarksman_PagesLocations |
| nordicmarksman_Pages_Lang |
| nordicmarksman_ProductCoupons |
| nordicmarksman_ProductDiscounts |
| nordicmarksman_ProductImages |
| nordicmarksman_ProductImages_Lang |
| nordicmarksman_ProductOptionLinks |
| nordicmarksman_ProductOptionNames |
| nordicmarksman_ProductOptionNames_Lang |
| nordicmarksman_ProductOptionValues |
| nordicmarksman_ProductOptionValues_Lang |
| nordicmarksman_ProductTabLinks |
| nordicmarksman_ProductTabs |
| nordicmarksman_ProductTabs_Lang |
| nordicmarksman_ProductUpsell |
| nordicmarksman_Products |
| nordicmarksman_Products_Lang |
| nordicmarksman_Purchases |
| nordicmarksman_PurchasesAffiliates |
| nordicmarksman_PurchasesCustomers |
| nordicmarksman_PurchasesData |
| nordicmarksman_PurchasesExtras |
| nordicmarksman_PurchasesGifts |
| nordicmarksman_PurchasesInvoices |
| nordicmarksman_PurchasesProgress |
| nordicmarksman_Regions |
| nordicmarksman_Reviews |
| nordicmarksman_Session |
| nordicmarksman_Settings |
| nordicmarksman_Shipping |
| nordicmarksman_ShippingMethods |
| nordicmarksman_ShippingPostalZip |
| nordicmarksman_ShippingZones |
| nordicmarksman_SubscriptionProducts |
| nordicmarksman_SubscriptionProfiles |
| nordicmarksman_TasksEmail |
| nordicmarksman_TasksQueue |
| nordicmarksman_TaxClasses |
| nordicmarksman_Taxes |
| nordicmarksman_URI |
| nordicmarksman_Users |
+-----------------------------------------+
It missed like half of them lol
Jimmacle
Jimmacle3mo ago
that suggests some other issue, maybe permissions it doesn't just randomly skip tables
UntoldTitan
UntoldTitanOP3mo ago
yeah
Jimmacle
Jimmacle3mo ago
you can enable more verbose logging in the scaffolding tool and see if there are any clues
UntoldTitan
UntoldTitanOP3mo ago
ill try that Got it to scaffold again, still skipping a bunch of tables. I'm using the root DB account, so it should have all the permissions it needs? verbose doesn't seem to show anything either
Jimmacle
Jimmacle3mo ago
what if you try to explicitly scaffold a table that it's skipping? with --table
UntoldTitan
UntoldTitanOP3mo ago
It just does nothing
dotnet ef dbcontext scaffold "server=127.0.0.1;uid=root;pwd=password;database=nordic" Pomelo.EntityFrameworkCore.MySql
-f -v --table nordic.nordicmarksman_Products
dotnet ef dbcontext scaffold "server=127.0.0.1;uid=root;pwd=password;database=nordic" Pomelo.EntityFrameworkCore.MySql
-f -v --table nordic.nordicmarksman_Products
thats the command I used -f to overwrite the DbContext Correction, it doesn't do nothing, it just creates the DbContext and nothing else I even tried switching providers from Pomelo.EntityFrameworkCore.MySql to the official MySql.EntityFrameworkCore package, exact same thing. Same tables too Its only doing the top 15 tables
Jimmacle
Jimmacle3mo ago
weird, i haven't seen that before what if you do something like a raw ado.net query to test if you can even access the tables from C# at a basic level?
UntoldTitan
UntoldTitanOP3mo ago
No description
UntoldTitan
UntoldTitanOP3mo ago
Just tried that, same error
Jimmacle
Jimmacle3mo ago
what if you make the same query in a non C# query console/tool?
UntoldTitan
UntoldTitanOP3mo ago
actaully i mistyped the table name hold on Yea same thing, doesn't exist doing that command directly on the DB returns the table as it should
Jimmacle
Jimmacle3mo ago
maybe we just blame mysql and pick a different database :PepeLaugh:
UntoldTitan
UntoldTitanOP3mo ago
I would love to Now here's something interesting I connected to the DB using WSL, (the database is running inside a docker container atm) and it can't find the table
UntoldTitan
UntoldTitanOP3mo ago
No description
UntoldTitan
UntoldTitanOP3mo ago
There we go, it litterally cannot see the tables. what a strange issue lmao
Jimmacle
Jimmacle3mo ago
Stack Overflow
MySQL > Table doesn't exist. But it does (or it should)
I changed the datadir of a MySQL installation and all the bases moved correctly except for one. I can connect and USE the database. SHOW TABLES also returns me all the tables correctly, and the fi...
Jimmacle
Jimmacle3mo ago
maybe this is related? if you copied the database you might have missed some metadata files that it needs
UntoldTitan
UntoldTitanOP3mo ago
Its a clone of a db, so possibly actually
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
UntoldTitan
UntoldTitanOP3mo ago
:kekw: I'm losing my mind
Jimmacle
Jimmacle3mo ago
if it's not that then i would have to say it's some kind of configuration/permission issue with external connections but i don't touch mysql for other reasons so idk
UntoldTitan
UntoldTitanOP3mo ago
Thats what i'm reading into at the moment Prolly something to do with visibility externally or something idk ive also never used mysql, and now I have the misfortune of using it for the first time on a project with a tight deadline lmao
Jimmacle
Jimmacle3mo ago
if you got the database from somewhere else is there someone there that you can ask for help?
UntoldTitan
UntoldTitanOP3mo ago
Yea, but conveniently he just went out of office for the week yesterday :broyai: anyways, thank you for your help figuring this one out, I'll take it from here
MODiX
MODiX3mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server