Skip to main content

55 posts tagged with "MySQL"

MySQL Relational Database Server and Its Tools

View All Tags

Fixed: "ERROR 1264 (22003): Out of range value for column 'UnitPrice' at row 1" in MySQL

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

ERROR 1264 (22003): Out of range value for column means the number you're saving doesn't fit the column's type. For a DECIMAL column, the limit isn't the number of decimals, which MySQL quietly rounds, but the number of digits before the decimal point. This post finds a column's exact limit, shows the difference between a value that's rounded and one that's refused, and fixes it from both sides: the column and the input.

Fixed: "ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails" in MySQL

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails means you inserted or updated a row that points at a parent which doesn't exist. I got it from my own mistake: I guessed that a new category had Id 3, because it was the third one I'd created. It wasn't. This post shows why the guess was wrong, how to find the right Id, how to insert without guessing, and how to answer 400 Bad Request from a .NET C# API.

Fixed: "ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails" in MySQL

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails means the row you're deleting is still in use: another table points at it through a foreign key, and that foreign key forbids the delete. The message even tells you which table and column. This post reads it piece by piece, finds the rows that block the delete, shows two ways to clear them, and turns the error into a 409 Conflict in a .NET C# API.

Fixed: "ERROR 1062 (23000): Duplicate entry 'adapters' for key 'categories.IX_categories_Name'" in MySQL

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

ERROR 1062 (23000): Duplicate entry … for key … means a unique index refused a value that already exists. Usually that's the index doing its job. The surprise in my case was which value counted as a duplicate: MySQL refused adapters because Adapters was already there. This post explains why, how to choose the behaviour you want, and how to handle the error cleanly in MySQL and in a .NET C# API.

Fixed: "ERROR 3819 (HY000): Check constraint 'CK_products_UnitPrice' is violated." in MySQL

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

MySQL enforces CHECK constraints, and it tells you when a row breaks one: ERROR 3819 (HY000): Check constraint '…' is violated. I met it twice in one afternoon: first when an EF Core migration tried to add constraints to a table that already held a bad row, then when a new row broke the rule. Both have the same cause and the same kind of fix, and in a .NET C# API the error can become a clear 400 Bad Request instead of a crash.

Fixed: "ERROR 1064 (42000): You have an error in your SQL syntax … near 'IF NOT EXISTS(SELECT * FROM `__EFMigrationsHistory`'" in an EF Core Idempotent Migration Script

· 13 min read
Jagdish Kumawat
Founder @ Dewiride

An EF Core migration script made with dotnet ef migrations script --idempotent failed in MySQL 9.7 at line 8 with ERROR 1064 (42000). Oracle's EF Core provider for MySQL writes the script's "skip what's already applied" checks as SQL Server-style IF NOT EXISTS(…) BEGIN … END blocks, and MySQL accepts that kind of block only inside stored procedures and other stored programs. The fix is a plain script that starts at the database's last applied migration.

How to Connect a .NET C# Web API to a MySQL Database — Part 1: Connect with EF Core and a Secure Connection String

· 42 min read
Jagdish Kumawat
Founder @ Dewiride

A Web API needs somewhere to keep its data, and MySQL is one of the most popular places to keep it. This part connects an ASP.NET Core minimal API, written in .NET 10 and C#, to MySQL 9.7 through Entity Framework Core. It keeps the password out of the code, encrypts the connection, proves the connection works with a health check, and then looks at that same connection from inside MySQL so you can see exactly what happened.

How to Check if a MySQL Connection Uses TLS

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

An encrypted connection keeps your password and your data private on the way to MySQL. MySQL 9.7 sets up encryption by itself and uses it whenever it can, but the mysql client in Docker can show SSL: Not in use, and that is fine. This guide shows how to check any connection, why a Unix socket is different, and how to insist on encryption.

How to Check the MySQL Character Set and Collation

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

The character set decides which characters MySQL can store, and the collation decides how it compares and sorts them. Get them wrong and emoji fail to save, or café and cafe turn out to be "equal" when you didn't expect it. This guide checks both at the server, database and connection level, and proves what the default utf8mb4_0900_ai_ci really does.

How to Check the MySQL Version

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

Before you follow a guide, report a bug or plan an upgrade, you need to know exactly which MySQL you're talking to. MySQL tells you in several places, and one of them works without signing in at all. This guide shows five ways, with real output from MySQL 9.7.4 in Docker, and the one place where the version you see can mislead you.

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.