C
C#3mo ago
morry329#

MySqlException: Column 'Age' cannot be null

So this error occured in the following scenario: I have created a simple ASP.NET Core web app with some simple db configurations. On running dotnet run from Rider, the browser displayed my web app (a login form). I have click "register a new user". Then I was redirected to a register form page with three textfields , email, password and repeat password. I filled in all of them and hit register. Now I was bugged with this bunch of exception texts https://pastebin.com/7DqbUai5 I don't understand this error Column 'Age' cannot be null. I made extra sure that my DB has the column Age with non-null values like this:
mysql> SELECT * FROM PortalUsers;
+---------------+------+-------------+-------------------------------------------------+
| Name | Age | Location | DisplayInfo |
+---------------+------+-------------+-------------------------------------------------+
| Alice Smith | 30 | New York | Name: Alice Smith Age: 30 Location: New York |
| Bob Johnson | 25 | Los Angeles | Name: Bob Johnson Age: 25 Location: Los Angeles |
| Charlie Brown | 35 | Chicago | Name: Charlie Brown Age: 35 Location: Chicago |
+---------------+------+-------------+-------------------------------------------------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM PortalUsers;
+---------------+------+-------------+-------------------------------------------------+
| Name | Age | Location | DisplayInfo |
+---------------+------+-------------+-------------------------------------------------+
| Alice Smith | 30 | New York | Name: Alice Smith Age: 30 Location: New York |
| Bob Johnson | 25 | Los Angeles | Name: Bob Johnson Age: 25 Location: Los Angeles |
| Charlie Brown | 35 | Chicago | Name: Charlie Brown Age: 35 Location: Chicago |
+---------------+------+-------------+-------------------------------------------------+
3 rows in set (0.00 sec)
` For your reference this is the link to the codes https://pastebin.com/k88fKn7r Could anyone point me in the right direction? I want to solve this error but I need another set of eyes PS: I am just thinking that this error may refer to the column Age which belongs to another table from another DB. The output displayed here came from the table PortalUser in the searchhome DB, but I may have another PortalUser table in my second DB. If that is the case will this error point to that another PortalUser which may have no column values? Hope all this makes sense.
Pastebin
fail: Microsoft.EntityFrameworkCore.Database.Command[20102] Fa...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
//Model class with the columns like 'Age'using Microsoft.AspNetCore...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
1 Reply
mg
mg3mo ago
in the 2nd line of the exception @p2=NULL (Nullable = false) (Size = 4000) which is the Age column you need to mark the column as nullable if you want to insert null values or you need to provide a value for Age for every user that's created yes, the users in the database right now all have ages, but because the Age column is not nullable, every user must have an age when it's created that exception is also coming from tying to insert into the AspNetUsers table, not PortalUsers
Want results from more Discord servers?
Add your server