I have a stored procedure that inserts a row into a table with an autoincremented column. It gives me a warning but succeeds if i simply put "" for the value of the autoincremented column. The way I get rid of the error currently is to specify which columns the insert values are for... "insert into app_table(app_id,name,...) values(...)" but the autoincremented column is the only one that isn't inserted into. Is there a cleaner way to do this? Like specifying which columns not to insert values into?
If you don't want to provide values for all columns, you should specify which columns you want to insert.
There are no shortcuts except *
.
How could there be a cleaner way to do it than populating every column except the id (and any other fields you want to leave default or null)? When you do it that way, you simply leave out the information that is automatically generated, so it requires less parameters than any other way of doing it, which would seem to be the cleanest way.
You're probably getting this warning:
mysql> show warnings;
+---------+------+------------------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------------------+
| Warning | 1264 | Out of range value adjusted for column 'id' at row 1 |
+---------+------+------------------------------------------------------+
1 row in set (0.00 sec)
Instead of ""
for the auto_increment column, use NULL
and the warning will go away. The auto_increment value will get incremented correctly. No need to list out all of the columns in the insert
statement (although many consider it a good practice).