Migrated MySQL database, now seeing "Field doesn't have a default value" - php

I was running an older version of MySQL through WAMP, and just migrated the databases to an IIS-based server with PHP and MySQL 5.6 installed. For any query I run where not all columns of the table are specified, I receive a message such as:
Field 'J_param2' doesn't have a default value
All columns are TEXT and have the "NOT NULL" attribute set, but it's my understanding that NULL and an empty string are different. I'm fine with the empty string. Rather than altering the hundreds of tables, is there any easier way to fix this?
Thanks for the assistance.

You can remove the NOT NULL and you should be fine.
Try:
ALTER TABLE table_name MODIFY COLUMN J_param2 TEXT;

Related

Incorrect integer value '' for a MySQL column that's integer and allow null?

I'm working on inserting a CSV into a table. I don't have any control over what's in the CSV and a lot of the fields are blank. In my very first record for instance, the field "baths_full" is just empty (two commas back to back).
On my production server running MySQL 5.5.37, it inserts the record with the baths_full as an empty field. On my local machine running MySQL 5.6.19, it gives me the error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'baths_full' at row 1 (SQL: insert into `listings_queue` (`
The weird thing is that the schema for the tables is identical. In fact, I used the export of the production machine to create the local database.
The field baths_full is set to TinyInt, unsigned, allow null, default null. One thing to add is that it looks like in the SQL insert statement Laravel is creating, it is treating null values as spaces. Regardless, my production machine runs the script without trouble but locally it won't run.
I found my problem. My local MySQL is running in strict mode. The answer from this thread (General error: 1366 Incorrect integer value with Doctrine 2.1 and Zend Form update) fixed it.
If the database column already contains a value of different data type not the same with the one you are changing to can throw error 1366, for example if a string value is already in one column of the table you are changing to tinyint. I once ran into this.
why not try type casting it to integer before inserting?
array( 'baths_full' => (int) $baths_full, ... )
like
"VALUES(".((int) $baths_full).")"

error while inserting null data in mysql phpmyadmin

Whenever I am inserting any blank data in my table it works on XAMPP but it does not work on my IIS server having PHP version 5.3 and MySQL version 5.5 I found error. What setting should I do in my configuration file so that any null value and blank data can be inserted, not only that if my table has five columns and if in one query page only two data is to be inserted rest is not written then also it shows error which is
insert failed Field 'XXX' doesn't have a default value
insert failed Data truncated for column 'Man_Days' at row 1
Is there any setting changes which can be done in my.ini or php.ini or config.inc.php
Firstly You must try to avoid inserting blank data in table. if it's not possible then try to insert the field which have value. So You may try to use Your mysql insert query like below:-
insert into table_name (field1,field3) values(value1,value2);

error #1146 in phpMyAdmin in XAMPP

I did something dumb. I'd imported the create tables sql file twice. That's not the worst part however. I then proceeded to trying to drop the duplicate tables from the phpMyAdmin database. This is all that loads up when I click on phpMyAdmin now:
Error
SQL query: Edit
SELECT `tables`
FROM `phpmyadmin`.`pma_recent`
WHERE `username` = '[myusername]'
MySQL said:
#1146 - Table 'phpmyadmin.pma_recent' doesn't exist
As in, just the above on an otherwise blank, white page.
EDIT
Everything returns to normal when I comment out the "Advanced Features" section in the config.inc.php file (the red exclamation signs are still beside everything, but I'm starting to wonder if that's just the default icon choice for phpMyAdmin 4.0.1). Once I uncomment them, the above returns. I've also noticed that the tables seems to be empty (maybe the reason for the exclamation signs?). Does that mean anything?
Check whether the tables inside phpMyAdmin database have two underscores __ after the pma prefix. If that is the case, update the entries in you config.inc.php with an additional underscore.
It looks like you accidentally dropped one or more of your built-in databases/tables that keep phpmyadmin running. The easiest solution is probably just to re-install XAMPP so you don't leave anything bugged by trying to do patchwork.
Just back up all of your created data.
I think specifically, you dropped the table that phpmyadmin stores your username in. Now you have no usernames stored in it and therefore you can't log into phpmyadmin.
I had the same problem, I'm not too sure why. Commenting out the advanced parts does work. Probably not the best way to go about it, but I'm sure that works for some people.
I got the same issue as you but I found a way to solve it.
from the create_tables.sql you got this:
-- Table structure for table pma_recent
CREATE TABLE IF NOT EXISTS pma__recent (
username varchar(64) NOT NULL,
tables text NOT NULL,
PRIMARY KEY (username)
)
COMMENT='Recently accessed tables'
DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
the table name (pma__recent)contents two underscore characters by default, just remove one of them and recreate all the tables again by copy/paste the script into the SQL tab for phpmyadmin window. You should do the same thing for the others table name.

ID cannot be null (Auto Increment)

I'm using an INSERT ON DUPLICATE KEY statement for my website. It's for creating news items, so I figured I could use the same MySQL command for both creating and updating news items.
However, when I use the following:
INSERT INTO table (id,title,content) VALUES(NULL,"Test","Test");
Instead of creating a new auto increment value it throws an error. However, the command works on my main development server. But not on my laptop. Both versions of MySQL are the same, the only difference being MySQL was installed manually on my server, and with WAMP on my laptop.
Are there any MySQL Variables that could be causing this?
I would suggest using INSERT INTO table (title,content) VALUES("Test","Test");
This will create a new row in the table with a new incremented ID.
Managed to solve it as best as I can.
I checked my code and found that when I inserted the empty POST'd ID was wrapping it in quotations. I've now changed it so that it puts NULL without quotations. So my query should now look like:
INSERT INTO table (id,title,content) VALUES(NULL,"test","Test")
ON DUPLICATE KEY UPDATE title=VALUES(title), content=VALUES(content);
That now works.
I think you should make query like this,
INSERT INTO table (title,content) VALUES("Test","Test");
If it still doesn't work then check if id column is set as auto-increment or not.

Zend_Db_Table insert issue with large content

I've been using Zend Framework for quite a while now, but now I have an issue that's got me puzzled. I have a table (MySQL) with just 2 columns (id and msg). The id field is an auto increment value and the msg field is a longtext type.
The following code should work just fine for inserting a record into the table:
$t = new Zend_Db_Table('table1');
$id = $t->insert(array('msg' => $content));
Whenever $content is just a plain string value like 'blah', it works just fine, like it should.
But the fieldtype is not a longtext type for no reason, the content will be quite large.
So now I try to place about 14kb of data in $content, no exception occurs, the database insert seems to have worked, but only for the first 6kb. The rest of the data is just gone?!
When I try to use to oldfashioned mysql_connect, mysql_query, etc routines, it all works like a charm. So it's really seems to be a Zend framework issue...
Has anybody else experienced this?
Configuration
Zend Framework v1.11.10
Zend_Db_Table is configured with the PDO_MYSQL adapter
MySQL database table two columns; id (autoincrement)
Issue
Attempting to INSERT 14kb of UTF8-encoded HTML into longtext column
Zend_Db_Table truncates the data at 6kb
Tests
mysql_query can INSERT the same data without issue
Zend_Db_Table can SELECT all the data without issue
setting error_reporting(-1) reveals 'no errors, warnings or notices'
mediumblob works fine
Isolating the issue
Change the column to a mediumtext. Does the insert work now?
Have you checked what the query actually looks like? See comment above from namesnik.
How many bytes get written on the failed inserts? Is it consistent?

Categories