Trouble running $wpdb->query() with last_insert_id

You can get the last inserted ID from $wpdb with the insert_id property:

$wpdb->insert( ... );
$couponId = $wpdb->insert_id

error code: 523