Hi i am very new in drupal. i just create a module that create a form with some inputs. I wrote .install file for the same but it is not creating table. While i am installing this module it is neither showing error nor install table.
function mycontact_schema() {
$schema['mycontact'] = array(
'description' => t('This table for mycontact.'),
'fields' => array(
'mycontctid' => array(
'description' => t('The primary identifier for a mycontact.'),
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE),
'vid' => array(
'description' => t('The current {mycontact_revisions}.vid version identifier.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0),
'name' => array(
'description' => t('The {mycontact_name} of this mycontact.'),
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => ''),
'email' => array(
'description' => t('The name of this contact, always treated a non-markup plain text.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''),
),
'comments' => array(
'description' => t('The comments of this contact, always treated a non-markup plain text.'),
'type' => 'text',
'not null' => TRUE,
'default' => ''),
'primary key' => array('mycontctid'),
);
return $schema;
}
It is not showing any error and any warning.
There is nothing wrong in the hook_install implementation.
I followed these steps to get it working:
Created a directory called mycontact inside sites/all/modules.
Created a the files mycontact.info, mycontact.module, and mycontact.install.
Inside mycontact.info I added the following lines:
name = my contact
core = 7.x
And in the mycontact.install file, I copied all the code from the question as it is.
Left the mycontact.module file empty. Note: Drupal needs this empty file.
Enabled the module. And it worked!
What you could do now is, disable the module -> uninstall it -> follow the above steps to install the module; and you should have your database table created for you.
Related
I added some content Fields which looks as it follows;
$temporaryColumnHC = array(
'my_type' => array(
'exclude' => 0,
'label' => 'My Type',
'config' => array(
'type' => 'select',
'renderType' => 'selectSingle',
'items' => array(
array('Bar', 'bar'),
array('Pie', 'pie'),
array('Donut', 'donut'),
array('Line', 'line'),
array('Bar 2', 'bar2'),
array('Bar 3', 'bar3'),
array('Bubble', 'bubble'),
)
)
),
'my_suffix' => array(
'exclude' => 0,
'label' => 'My Label Suffix',
'config' => array(
'type' => 'input',
'size' => 10,
'max' => 20
)
),
'my_source_url' => array(
'exclude' => 0,
'label' => 'Source URL',
'config' => array(
'type' => 'input',
'renderType' => 'inputLink'
)
),
'my_source' => array(
'exclude' => 0,
'label' => 'Source Text',
'config' => array(
'type' => 'text',
'cols' => 40,
'rows' => 15
)
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
$temporaryColumnHC
);
but on save I get the following error
error [1620]: Unknown column 'suffix' in 'field list'
What I have to do that this fields is saved in database
As mentioned already as a comment, TYPO3 complains that the column is missing in the Database.
Your extension should provide an ext_tables.sql which extends the Database Schema. See https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ExtensionArchitecture/FilesAndLocations/Index.html#ext-tables-sql for further information.
The file always contains CREATE TABLE statements, which will be converted by TYPO3 do update the schema.
Updating the schema can be done through the install tool of TYPO3, or tools like TYPO3 console via command line.
Could someone tell me if I've missed something in this? It keeps throwing the error mentioned at the bottom after the code block.
function license_update_7101() {
$schema['license_agreements'] = array(
'description' => 'License User Agreements',
'fields' => array(
'license_id' => array(
'description' => 'Primary key for license records',
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE
),
'user_id' => array(
'description' => 'License agreed to by User ID',
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
'default' => '0'
),
'product_id' => array(
'description' => 'Product ID that represents the product this agreement was assigned to.',
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
'default' => '0'
),
'session' => array(
'description' => 'Session created during account creation.',
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
'default' => ''
),
'agreed' => array(
'description' => 'Represents if the license was agreed to or not',
'type' => 'int',
'size' => 'tiny',
'not null' => FALSE,
'unsigned' => TRUE,
'default' => '0'
),
'agreement_date' => array(
'description' => 'Date this license was agreed to by user.',
'type' => 'datetime',
'mysql_type' => 'DATETIME',
'disp-width' => '11',
'not null' => FALSE,
'default' => NULL
),
'blog_name' => array(
'description' => 'URL for actual product license belongs to.',
'type' => 'varchar',
'length' => '128',
'not null' => FALSE,
'default' => ''
),
'primary key' => array('license_id')
)
);
db_create_table('license_agreements', $schema['license_agreements']);
}
ERROR:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB [error]
server version for the right syntax to use near 'DEFAULT NULL
) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'License' at line 9
Really would love to get this solved.
Thanks!
So, courtesy of having another dev come help me try to find what was blowing things up, I managed to discover the issue as we worked through it.
'primary key' => array('license_id')
I ended up noticing that that was embedded within the fields array and needed to be outside/after it.
So, the fix was as simple as moving that line down as an array element of the license_agreements array. Problem solved!
I have created a WordPress theme options page in which all options/settings are in an array. Now those strings in the arrays refuse to be translated.
How can I get it so that the strings in my arrays will be translated?
// create theme options
global $cc_options;
$cc_options = array (
// General settings
array( 'name' => __('General', 'cc_language'),
'slug' => 'general',
'status' => 'active',
'type' => 'section'),
array( 'name' => __('Setup some general settings for the website.', 'cc_language'),
'type' => 'section_desc'),
array( 'type' => 'open'),
array( 'name' => __('Breadcrumbs', 'cc_language'),
'type' => 'section_category'),
array( 'name' => __('Enable breadcrumbs', 'cc_language'),
'desc' => __('Check to enable breadcrumbs on pages and posts.', 'cc_language'),
'id' => 'breadcrumbs',
'type' => 'checkbox',
'std' => 'true'),
array( 'type' => 'close'),
);
Your options array needs to be defined after wordpress has initalized its translation routines. Try putting the declaration in an init action hook.
I'm having issues with using the schema module and a table I created. I used schema to create the schema and then when I tried to install the module logo_management, I get this error:
Invalid default value for 'logoid':
CREATE TABLE {logo} ( `logoid` INT unsigned NULL auto_increment DEFAULT
0 COMMENT 'Unique Logo ID', `date_created` NULL DEFAULT 0 COMMENT
'The date the logo was added.', `category` VARCHAR(50) NULL DEFAULT
'OTHER' COMMENT 'The category the logo should be in.', `no_of_lines`
INT NULL DEFAULT 1 COMMENT 'Number of lines(1 or 2)',
`line_1` VARCHAR(100) NULL DEFAULT NULL COMMENT 'Line 1 for Logo',
`line_2` VARCHAR(100) NULL DEFAULT NULL COMMENT 'Line 2 for Logo',
`image_path` VARCHAR(100) NULL DEFAULT NULL COMMENT
'Path and filename for image', `activate`
INT NULL DEFAULT 0 COMMENT 'Boolean if the logo should be active or not.',
PRIMARY KEY (`logoid`) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT
Here is the .install schema I have. I'm assuming it's something wrong with the Invalid default value for 'logoid', however I tried putting the default value and it still gives me the same error.
function logo_management_schema() {
$schema['logo'] = array(
'description' => 'Logo Management Module',
'fields' => array(
'logoid' => array(
'description' => 'Unique Logo ID',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'date_created' => array(
'description' => 'The date the logo was added.',
'type' => 'date',
'not null' => TRUE,
),
'category' => array(
'description' => 'The category the logo should be in.',
'type' => 'varchar',
'length' => '50',
'not null' => TRUE,
'default' => 'OTHER',
),
'no_of_lines' => array(
'description' => 'Number of lines(1 or 2)',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'line_1' => array(
'description' => 'Line 1 for Logo',
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
),
'line_2' => array(
'description' => 'Line 2 for Logo',
'type' => 'varchar',
'length' => '100',
'not null' => FALSE,
),
'image_path' => array(
'description' => 'Path and filename for image',
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
),
'activate' => array(
'description' => 'Boolean if the logo should be active or not.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('logoid'),
);
return $schema;
}
Skill and determination fixed this problem! Changed the type to int.
$schema['logo'] = array(
'description' => 'Logo Management Module',
'fields' => array(
'logoid' => array(
'description' => 'Unique Logo ID',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
)
Then I ran into a date problem and changed it to this:
'date_created' => array(
'description' => 'The date the logo was added.',
'type' => 'datetime',
'mysql_type' => 'DATETIME',
'not null' => TRUE,
),
Now my module installs!
Any help would be brilliant.
function request_gold_pack_schema() {
$schema['request_gold_pack_customer_details'] = array(
'description' => 'Table to store all customer details.',
'fields' => array(
'rid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'auto increment' => TRUE
),
'title' => array(
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'default' => ''
),
'first_name' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => ''
),
'last_name' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => ''
),
'house_name_no' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => ''
),
'street' => array(
'type' => 'varchar',
'length' => 160,
'not null' => TRUE,
'default' => ''
),
'town' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => ''
),
'county' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => ''
),
'telephone' => array(
'type' => 'int',
'length' => 12,
'not null' => TRUE,
'default' => ''
),
'email' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'date_registered' => array(
'mysql_type' => 'DATETIME',
'not null' => TRUE
),
'primary' => array(
'rid'
)
)
);
return $schema;
}
which gives me the following errors
Notice: Undefined index: type in DatabaseSchema_mysql->processField() (line 205 of /Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/mysql/schema.inc).
Notice: Undefined index: :normal in DatabaseSchema_mysql->processField() (line 205 of /Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/mysql/schema.inc).
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT NULL ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'Table to stor' at line 13: CREATE TABLE {request_gold_pack_customer_details} ( rid INT NOT NULL DEFAULT 0, title VARCHAR(10) NOT NULL DEFAULT '', first_name VARCHAR(50) NOT NULL DEFAULT '', last_name VARCHAR(50) NOT NULL DEFAULT '', house_name_no VARCHAR(50) NOT NULL DEFAULT '', street VARCHAR(160) NOT NULL DEFAULT '', town VARCHAR(50) NOT NULL DEFAULT '', county VARCHAR(50) NOT NULL DEFAULT '', telephone INT NOT NULL DEFAULT '', email VARCHAR(255) NOT NULL DEFAULT '', date_registered DATETIME NOT NULL, primary DEFAULT NULL ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'Table to store all customer details.'; Array ( ) in db_create_table() (line 2688 of /Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/database.inc).
Been trying to find a solution for hours.
Thanks.
It is an issue with your primary key. You hve it listed in the fields array (it should not be) and it should be referenced as 'primary key' and not 'primary', like so:
function request_gold_pack_schema(){
$schema['request_gold_pack_customer_details'] = array(
'description' => 'Table to store all customer details.',
'fields' => array(
// Your field definitions
),
'primary key' => array(
'rid'
)
);
return $schema;
}
Check out the schema api documentation on drupal.org.
I would also recommend setting the rid field to type serial and leaving off the auto increment parameter (Drupal will handle that). So the 'rid' field definitions would be as such:
'rid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
)
You have to specify the size in drupal 7 for type 'int'...i.e
'rid' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'auto increment' => TRUE,
),
the size can be normal,tiny,big
check drupal 7 datatypes.