java.sql.SQLException: Field 'userid' doesn't have a default value at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:130) ~[mysql-connector-j-8.3.0.jar:8.3.0]
@Entity
@Table(name = "users")
public class Users {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int userId;
}
CREATE TABLE `users` (
`user_id` int NOT NULL AUTO_INCREMENT,
`email` varchar(255) DEFAULT NULL,
`is_active` bit(1) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`registration_date` datetime(6) DEFAULT NULL,
`user_type_id` int DEFAULT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `UK_6dotkott2kjsp8vw4d0m25fb7` (`email`),
KEY `FK5snet2ikvi03wd4rabd40ckdl` (`user_type_id`),
CONSTRAINT `FK5snet2ikvi03wd4rabd40ckdl` FOREIGN KEY (`user_type_id`) REFERENCES `users_type` (`user_type_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
when i make insert i get that error:
Error Code: 1364. Field 'userid' doesn't have a default value
There is a mismatch typing names. in your Users entity class, the field is called userId, but in your MySQL table, the column is named user_id. To resolve this issue, you need to ensure that the names used in the Java entity class match those in the database table schema. You can fix this by modifying your entity class to include the correct column name using the @Column annotation:
@Entity
@Table(name = "users")
public class Users {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id") // Make sure this matches the column name in your table
private int userId;
}