Closed (won't fix)
Project:
Content Construction Kit (CCK)
Version:
5.x-1.6-1
Component:
General
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
9 Jan 2007 at 21:14 UTC
Updated:
11 Jan 2012 at 16:35 UTC
When I add a text field to a content type, I get a warning message :
The column is not created in the database table. I can create it manually by executing the SQL query without "default '' ".
I have read that I get this error because MySQL (5.0.27) runs in strict mode, but I have also read that Drupal 5.0 should be compatible with strict mode.
Next I have some trouble when I want to add a node. I get a suite of error messages :
I understand that this is because the is no default values for text in database, but I do not understand why the insert is not done with a single SQL command like :
Frederic
Comments
Comment #1
karens commentedWe need to know what type of field you were creating in the first instance and updating in the second. You can make this easier by enabling the content_copy module that comes bundled with CCK and exporting the content type(s) in question and pasting the export here so we can see how you have the fields set up.
The program doesn't do a single update command because fields are not necessarily in the same table. Sometimes they are all in different tables, sometimes one or more are in the same table and another is in a different table. Instead of convoluted logic trying to figure out how many inserts are needed and which can be grouped, each is performed separately. Plus, CCK works by cycling through each field module, allowing it to do its own processing, and then inserting/updating it, so doing one query at a time fits best into the processing flow.
Comment #2
flebas commentedFields are text fields in both cases. Text/Text field when creating, Text/Text field and Text/Select list when updating.
I created a new content type, athen added a new textfield and I get this error : user warning: BLOB/TEXT column 'field_text_field_value' can't have a default value query: content_db_add_column ALTER TABLE node_cckbug ADD COLUMN field_text_field_value longtext NOT NULL default '' in D:\Inetpub\wwwroot\Fireball\includes\database.mysqli.inc on line 151.
Export of new content type :
$content[type] = array ( 'name' => 'MyContent', 'type' => 'cckbug', 'description' => 'CCK/MySQL bug content', 'title_label' => 'Titre', 'body_label' => '', 'min_word_count' => '0', 'help' => '', 'node_options' => array ( 'status' => false, 'promote' => false, 'sticky' => false, 'revision' => false, ), 'comment' => '0', 'image_attach' => '0', 'upload' => '0', 'old_type' => 'cckbug', 'orig_type' => '', 'module' => 'node', 'custom' => '1', 'modified' => '1', 'locked' => '0', ); $content[fields] = array ( 0 => array ( 'widget_type' => 'text', 'label' => 'Text Field', 'weight' => '0', 'rows' => '1', 'description' => '', 'group' => false, 'required' => '0', 'multiple' => '0', 'text_processing' => '0', 'max_length' => '', 'allowed_values' => '', 'allowed_values_php' => '', 'field_name' => 'field_text_field', 'field_type' => 'text', 'module' => 'text', ), );
Comment #3
yched commentedSomething got mixed up when the fix in http://drupal.org/node/101946 got committed. The lines did not get added in the right place.
Possible reason is that the code is quite different in 4.7 and 5.0 branches, see below.
This should now be fixed in 1.x-dev branches, but could probably use some testing.
Side note to fellow cck maintainers :
the code is different in 4.7 and 5.0 because JonBob's commit for content_admin.inc 1.12.2.7 in 4.7 branch did not get backported to the HEAD branch at that time, and thus did not make it to the 5.0 branch.
It was supposed to fix things for pgsql, with the creation of the helper content_db_construct_column_type function, and some naughty stuff going on between $type and $basetype.
We do not have that in 5.0, and - same old same old - we do not really now how well it supports pgsql...
Comment #4
yched commentedPS to my technical mumble :
see http://drupal.org/node/74535 for the original pgsql patch - the issue got closed while waiting for a HEAD commit and we lost track of that when we arrived.
Comment #5
flebas commentedI have looked at 5.x-1.2 code.
There is some code to clear $default in content_db_add_column function (lines 1067 to 1071), but $default variable can be set later to some code (lines 1082, 1089).
If I add the patch just before the ALTER TABLE query, I can add fields without problem.
This easily fix the field creation problem, but the data insertion problem remains. Since there is no default values for text fields, the Insert command returns an error :
* user warning: Field 'field_lieu_value' doesn't have a default value query: INSERT INTO node_livre (field_reference_value, vid, nid) VALUES (123, 2, 2) in ..\includes\database.mysqli.inc on line 151.
Since there are some errors, I don't know exactly how SQL commands are executed. I presume that there is a first INSERT command to create the record then some UPDATE commands to set the field values for the same nid.
The first insert command should contain default values for all fields that do not have default value defined in the database :
INSERT INTO node_livre (field_reference_value, field_lieu, vid, nid) VALUES (123, '', 2, 2) .
Another solution that seems to work is to allow NULL values when creating text fields.
Comment #6
flebas commentedI see that is bug is marked as fixed but I think this is not the case. Only the problem of adding new fields is fixed, not the problem when adding node.
I had to manually edit database (change NOT NULL attribute to NULL on text columns) to add new content, and I don't know Drupal enough to tell if this change can have side effects. However, I think that full fix should include creation of fields with the proper attributes.
Comment #7
yched commentedIt was marked as fixed because was not aware we had another problem during data insert :-)
I'm not really sure what's the best way to fix this right now.
I'll try to investigate when I have some time
Comment #8
yched commentedUpdating to a less dramatic title
Does not mean we don't have to fix it though...
Comment #9
littleprince commentedHas there been an update to this? Seems more like a Drupal 5 bug than a CCK bug to me since I've noticed this on other modules such as Category. Was just wondering because I'm re-evaluating CMS for a huge website I need to work on and the Taxnomy of Drupal would make it an excellent choice over Joomla which I usualy use.
Comment #10
lias commentedThis error occurs no matter what type of field I try to add to a new content type using cck. I'm using MySql 5.0.1.8 and CCK // $Id: CHANGELOG.txt,v 1.1.4.16 2007/02/01 15:07:40 karens Exp $ 5--1.3 .
So it kind of makes adding fields and using CCk useless if I keep getting this error. So I wonder if it is ok to use the workaround :
manually edit database (change NOT NULL attribute to NULL on text columns) to add new content
that flebas offered?
I also use this CCK version on a server with MySQL 4x and adding fields works fine.
thanks.
lsabug
Comment #11
littleprince commentedI have tried manually creating the fields table in the database with the not null removed. Did not seem to have an adverse effect.
You can also remove the strict option from mysql if it's a local server.
This seems to me to be a problem with the core itself rather than CCK to me because multiple modules are having the same problem.
Comment #12
yched commentedJust to clear things a little:
the error reported by lsabug in #10 (error on creation of any field) is unrelated and should now be fixed : http://drupal.org/node/115332
What we have now is 'only' an error for text fields
Comment #13
liquidcms commentedok, just want to track this so thought i would add a post... since i was posting this problem on the "other" somewhat similar issue that yshed mentions in #12.
so just to state my findings.. which i think match above.
- i use drupal 4.7
- i use MySQL 5.0
i see this issue when i add a node that has a text field
i have fixed it in my cases by setting "allow null" on those fields
Peter Lindstrom
LiquidCMS - Content Management Solution Experts
Comment #14
Emmental commentedHere is the reason for the problem as I see it. MySQL 5 doesn't allow default values for text fields, and CCK is setting those fields to NOT NULL.
This wouldn't be a problem if CCK used a single query to insert data into the table since empty text fields would be entered as '' (which is not the same as null). In fact, if you only have a single text field defined in your content type (meaning no other fields at all) and leave it blank on the entry form then this is exactly what it does and it works fine.
However, because CCK uses a separate insert query for every field (the reasons for this were discussed elsewhere but I can't remeber where now) any text fields will throw the error when you have more than one field (of any type) because they are not being provided with a value.
So as long as CCK uses separate queries the only way I see to fix the problem is by allowing null entries in text fields. This can be done permanently by finding the following code in CCK's content_admin.inc at line 1338 (cck-5.x-1.x-dev):
and adding the $not_null line as shown:
This will mean that you will no longer have to manually change field definitions or MySQL settings. Note that this only applies to newly created fields and does not account for any changes that might be made by running Drupal's update.php. I'm not sure of any side-effects that may arise from this change, but other posters suggest that allowing nulls is fine.
Comment #15
yched commented@Emmental : that's a very precise sum up of the issue and of the probable 'best' fix for this - except $not_null should rather be set to '' (empty string), and that the same line should be added on 1438 as well.
I have been hesitating on this fix for a few weeks, but it's probably time to go ahead now :-)
So I'll probably be committing this when I have the update function (to take care of existing fields) ready.
Comment #16
yched commentedI committed the fix and the update function to DRUPAL-5 branch.
4.7 version tomorrow :-)
Comment #17
yched commentedfix committed to 4.7 branch.
This should be fixed now - however I don't have any MySQL 5 install to actually test, so please reopen if necessary
Comment #18
mordonez commentedI think the error its with the 'display_settings' column.
Comment #19
rssaddict commentedThis is still a problem. The display_settings field generates an error when using MySQL 5.0 in strict mode. The simple workaround is to put this code into the my.ini file:
sql_mode=MYSQL40This will make MySQL 5 behave like MySQL 4 and play nice with Drupal (this goes for the problem with the Aggregator module as well.)
Comment #20
yched commentedNo. The 'display_settings' error is another issue, absolutely unrelated to this one.
Both errors should be fixed in latest 1.x-dev package. We have a new official 1.4 release coming out pretty soon.
Meanwhile, _please_ make sure you're running latest 1.x-dev code, the 'display_settings' issue has been erroneously reported several times now.
If the error still happens, please report in http://drupal.org/node/115332
Comment #21
(not verified) commentedComment #22
liquidcms commentedsorry to re-open.. but not sure why this and the other related issue have both been closed when the issue still seems to prevail... or has it been moved to a new issue???
I have just finished my last 4.7 project and starting on a 5.1 project. I have what i think is latest version of CCK (5.x-1.5) and MySQL 5.
When i create a new node using custom cck type i get:
looks like the same issue to me.
Peter Lindstrom
LiquidCMS - Content Management Solution Experts
Comment #23
lias commentedSame issue I believe with latest cck versions, 5.1 and mysql 5.0.18:
# ser warning: Field 'field_phone2_value' doesn't have a default value query: INSERT INTO content_type_department (field_staff2_first, field_staff2_middle, field_staff2_last, vid, nid) VALUES ('Mist', '', 'Now', 30, 30) in D:\www\public_html\domain\includes\database.mysql.inc on line 172.
# user warning: Field 'field_phone2_value' doesn't have a default value query: INSERT INTO content_type_department (field_title2_value, vid, nid) VALUES ('Public Specialist', 30, 30) in D:\www\public_html\domain\includes\database.mysql.inc on line 172.
# user warning: Field 'field_phone3_value' doesn't have a default value query: INSERT INTO content_type_department (field_phone2_value, vid, nid) VALUES ('1 000-000-0000', 30, 30) in D:\www\public_html\domain\includes\database.mysql.inc on line 172.
# user warning: Field 'field_phone2_value' doesn't have a default value query: INSERT INTO content_type_department (field_staff3_first, field_staff3_middle, field_staff3_last, vid, nid) VALUES ('Lail', '', 'Sar', 30, 30) in D:\www\public_html\domain\includes\database.mysql.inc on line 172.
# user warning: Field 'field_phone2_value' doesn't have a default value query: INSERT INTO content_type_department (field_title3_value, vid, nid) VALUES ('Accountant/Internal Control Auditor', 30, 30) in
I entered in the content and created groups for staff member 1, 2, etc. The staff members after the first group created were not saved to the database and I got the error message. There are no naming conflicts afaik.
Comment #24
foxtrotcharlie commentedI'm getting a similar error using MySQL 5.0.27 and Drupal 5.2 when I add a new CCK node with some fields not filled in:
In my database I see that the email field and link fields (url and url_title in this case) do not allow null values and no default value is set.
When I change those fields to allow null values, I can add a node without any errors.
Comment #25
lias commentedSorry to be a downer but I am still experiencing this problem --when a user submits a cck node (in my case it's also an og node type) what they entered into the fields (text and an email field) is empty when submitted. I looked at my watchdog logs and found this:
Field 'field_email_email' doesn't have a default value query: INSERT INTO content_type_classroom (field_school_value, vid, nid) VALUES ('Administration', 74, 74) in D:\www\public_html\class\includes\database.mysql.inc on line 172.
and
Duplicate entry '73-0-og_public' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (73, 'og_public', 0, 1, 0, 0) in D:\www\public_html\class\includes\database.mysql.inc on line 172.
I'm not sure why I'm getting a duplicate entry when I've allowed for more than one group node to be created per user.
Here's my exported content type - classroom which is a group type:
I've got the latest versions of both cck and og. The strange thing is that some of the fields "stick" and retain the info. the user entered but other fields (like the first name, grade levels) don't. I thought by updating to the latest versions of each (using drupal 5.5 too) and MySQL 5.0.18/ PHP 5.1.2 that it would be good to go but no luck. Considering the code mod from comment http://drupal.org/node/108094#comment-489361 was back in Feb. 2007 I wasn't sure if I should do this.
Comment #26
newbuntu commentedI am using 5.6 and mysql, and still see the same problem. Trace into the code, the problem is still when there are "required" fields, which translate into database as "not null".
If there is only one "required" field that happens to be inserted first into content_type_xxx, then the insert would work, because rest of the "inserts" become "updates", therefore it works in that case. If other fields get inserted first, then it will cause problem.
Comment #27
dan.blah commentedWasn't having this issue on the dev server and found it to be an issue on the production server. This only started happening on one of many custom node types that are using all CCK fields.
Dev Server:
OS FreeBSD 6.2-STABLE
Web server Apache/2.2.6 (FreeBSD) mod_ssl/2.2.6 OpenSSL/0.9.8g DAV/2 PHP/5.2.5 with Suhosin-Patch
PHP 5.2.5
MySQL 5.0.45
Drupal 5.7
CCK 5.x-1.6-1
Production server:
OS Windows Server 2003
Web server Microsoft-IIS/6.0
PHP 5.2.5
MySQL 5.0.51a
Drupal 5.7
CCK 5.x-1.6-1
I am getting the above error for 17 of the fields that aren't a node reference field type.
Comment #28
dan.blah commentedif it helps, the messages i am getting. changing to not null as stated above doesn't do it for me.
Comment #29
dan.blah commentedI was able to get this to not be an issue by changing the following in the my.ini file on the production server:
# Set the SQL mode to strict
#original
#sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
More info @ http://dev.mysql.com/doc/refman/5.1/en/constraint-invalid-data.html
Comment #30
lias commentedBefore I modify my mysql.ini file I would like confirmation that this is the correct fix, I'm afraid of breaking other sites on the server that rely on mysql.
Thanks.
Comment #31
karens commentedThe D5 version is no longer being supported. Sorry.