I have made a table users with two fields: username and password. I have the password set as not null.
The problem is when I enter data and don’t include the password just the username I am able to insert values into the password field.
My goal is to not allow any entries into the database that dont have both a username and passwords. I thought the not null would enforce this but appears to just insert the empty string. Any suggestions?
You should post both your full table definition as well as the code that actually inserts a record.
However, most likely you either have a default value assigned as a blank string to the table. OR you are passing a blank string, as opposed to null, in your insert statement.
If the latter you should know that null is not the same as an empty string.
Another idea is to simply add an insert trigger where you test the password value to see if it meets requirements. If not, cancel the insert. I would normally have suggested that you use a check contraint, but apparently MySql doesn’t actually honor those.