I am trying to define relationship between tables using foreign keys
in drupal 7. I used hook_schema and hook_update function to define and
update the schema. I am getting following errors.
$schema['relationship] = array(
'description' => 'The table for employee organisation relationship',
'fields' => array(
'rid' => array(
'description' => 'The primary Identifier for a Relationship.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The primary Identifier for User/Employee',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
),
'oid' => array(
'description' => 'The department Identifier of employee employed',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
),
'indexes' => array(
'uid' => array('uid'),
'oid' => array('oid'),
),
'foreign keys' => array(
'uid' => array(
'table' => 'users',
'columns' => array('uid' => 'uid')
),
'oid' => array(
'table' => 'organization',
'columns' => array('oid' => 'oid')
),
),
'primary key' => array('rid'),
)
);
Failed: 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 'The table for' at line 5: CREATE TABLE
{organisation} ( id INT unsigned NOT NULL
auto_increment COMMENT 'The primary Identifier for a Relationship.',
uid INT unsigned NULL DEFAULT 0 COMMENT 'The primary Identifier for
User/Employee', oid INT unsigned NULL DEFAULT 0 COMMENT 'The
department Identifier of employee employed', primary key DEFAULT
NULL ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'The table
for employee organisation relationship'; Array ( ) in
db_create_table() (line 2717 of
C:\xampp\htdocs\tutumaudit\includes\database\database.inc).
Well I sorted it out myself. I put those keys under the fields array.
That was damn stupid and i needed 2 hours to find this out. The final
code is below:
$schema['relationship] = array(
'description' => 'The table for employee organisation relationship',
'fields' => array(
'rid' => array(
'description' => 'The primary Identifier for a Relationship.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The primary Identifier for User/Employee',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
),
'oid' => array(
'description' => 'The department Identifier of employee employed',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
),
),
'indexes' => array(
'uid' => array('uid'),
'oid' => array('oid'),
),
'foreign keys' => array(
'uid' => array(
'table' => 'users',
'columns' => array('uid' => 'uid')
),
'oid' => array(
'table' => 'organization',
'columns' => array('oid' => 'oid')
),
),
'primary key' => array('rid'),
);
Related
I created a metadata field named _metafield_gallery in a metabox.
On my production server the _metafield_gallery field contains datas when I display the array of the posts (query with get_posts).
After exporting the database from the production server to the local server when I try to display array of the posts datas with get_posts query, _metafield_gallery is empty.
The datas are present in the exported .sql file yet.
It's an authentification problem ?
register_post_meta(
$post_type,
'_metafield_gallery',
array(
'type' => 'array',
'single' => true,
'show_in_rest' => array(
'schema' => array(
'items' => array(
'type' => 'object',
'properties' => array(
'id' => array(
'type' => 'number',
),
'title' => array(
'type' => 'string',
),
'url' => array(
'type' => 'string',
),
)
),
),
),
'auth_callback' => function() {
return current_user_can( 'edit_posts' );
}
)
);
Production server :
[_metafield_gallery] => Array (
[0] => Array(
[id] => 21468
[title] => 11
[url] => https://mysite.fr/content/uploads/2022/07/11.png
)
)
Local server :
[_metafield_gallery] =>
I am using TL_DCA Feature in Contao and i want to wrap the fields inside left and right container.
$GLOBALS['TL_DCA']['table_name'] = array
(
// Config
'config' => array
(
'dataContainer' => 'Table',
),
// List
'list' => array
(),
// Fields
'fields' => array
(
'field1' => array
(
'label' => array('Suchname', 'Suchname'),
'exclude' => true,
'inputType' => 'text'
),
'field2' => array
(
'label' => array('Firma', 'Firma'),
'exclude' => true,
'inputType' => 'text'
),
'field3' => array
(
'label' => array('Name', 'Name'),
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory' => true)
),
'field4' => array
(
'label' => array('Vorname', 'Vorname'),
'exclude' => true,
'inputType' => 'text'
),
)
)
Wrap Field and Filed 2 inside left class and Field 3 and Field 4 inside right class. So please help here.
Thanks in advance..!!!
It's possible to specific css classes for the fields:
'eval' => array('tl_class'=>'w50'),
w50 stands for width = 50%
for example:
'field1' => array
(
'label' => array('Suchname', 'Suchname'),
'exclude' => true,
'inputType' => 'text',
'eval' => array('tl_class'=>'w50'),
),
'field2' => array
(
'label' => array('Firma', 'Firma'),
'exclude' => true,
'inputType' => 'text'
'eval' => array('tl_class'=>'w50'),
),
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am trying to create a table in Drupal database using hook_schema function but I am getting the PDO exception error which I could not resolve. It would be great if you could provide me an solution to my issue
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 '' COMMENT
'first name of the user', `lname` VARCHAR DEFAULT '' COMMENT' at line 3:
CREATE TABLE {mage_user} ( `uid` INT unsigned NOT NULL auto_increment COMMENT
'The foreign identifier for a mage user.', `fname` VARCHAR DEFAULT ''
COMMENT 'first name of the user', `lname` VARCHAR DEFAULT '' COMMENT
'last name of the user', `address1` VARCHAR(255) DEFAULT '' COMMENT
'adress line 1', `address2` VARCHAR(255) DEFAULT '' COMMENT 'adress line 2',
`postcode` VARCHAR(7) DEFAULT '' COMMENT 'postcode', `gender` VARCHAR(6)
DEFAULT '' COMMENT 'gender' ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8
COMMENT 'The base table for mage user.'; Array ( ) in db_create_table()
(line 2688 of E:\Server\drupal\includes\database\database.inc).
I am using
Apache/2.2.22 (Win32) PHP/5.3.10
MySQL client version: mysqlnd 5.0.8-dev - 20102224 - $Revision: 321634 $
MySQL server version 5.5.21
and my schema definition is
function mageacc_schema() {
$schema['mageuser'] = array(
'description' => 'The base table for mage user.',
'fields' => array(
'uid' => array(
'description' => 'The foreign identifier for a mage user.',
'type' => 'serial',
'not null' => TRUE,
),
'fname' => array(
'description' => 'first name of the user',
'type' => 'varchar',
'lenght' => 255,
'default' => '',
),
'lname' => array(
'description' => 'last name of the user',
'type' => 'varchar',
'lenght' => 255,
'default' => '',
),
'address1' => array(
'description' => 'adress line 1',
'type' => 'varchar',
'length' => 255,
'default' => '',
),
'address2' => array(
'description' => 'adress line 2',
'type' => 'varchar',
'length' => 255,
'default' => '',
),
'postcode' => array(
'description' => 'postcode',
'type' => 'varchar',
'length' => 7,
'default' => '',
),
'gender'=>array(
'description' => 'gender',
'type' => 'varchar',
'length' => 6,
'default' => '',
),
),
);
return $schema;
}
Thanks in Advance
I spotted a few typos with the 'length' property. Try fixing those first in fname and lname to see if it works.
I'm creating a custom module which enables me to add Countries to a custom table in the database. I'll do later more with it, but as I got stuck at the beginning, I can't go on.
First my piece of code:
function partners_schema()
{
$schema['partners_country'] = array(
'description' => 'TODO: please describe this table!',
'fields' => array(
'id' => array(
'description' => 'auto inc id of country',
'type' => 'serial',
'not null' => true,
),
'name' => array(
'description' => 'name of country',
'type' => 'varchar',
'length' => '255',
'not null' => true,
'translatable' => true,
),
'needDistributor' => array(
'description' => 'is a distributor needed',
'type' => 'int',
'size' => 'tiny',
'not null' => true,
),
),
'primary key' => array('id'),
);
return $schema;
}
The code above generates my Database table. After searching I found that I can add 'translatable' => true to my schema, so Drupal knows that this field is translatable content.
I've added a form, to insert data into that schema, but now I got stuck. What do I have to do, that the user is able to translate the column name?
Thanks for your help.
Have a look at the accepted answer on this post it should help clear a few things up.
I'm new to Drupal and want to make my own module for Drupal 7. But i don't understand the theming / templates system in drupal jet. So i will be ready glad if some one can help me with that. I'm building a twitter module that shows the latest tweets with a certain #hashtag. Loading the data is not the problem. The problem is choosing the best solution for displaying the data. I want to show it like this:
[the link to twitter author_url]
[title] by [author_url]
[close the link]
Thanks for the help.
twitter.install file: (my custom fields)
array(
'twitter_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'author' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'author_url' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'published' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => ''
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE
),
'description' => array(
'type' => 'text',
'not null' => FALSE
),
'link' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE
),
'image' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE
),
),
'primary key' => array('twitter_id'),
);
return $schema;
}
You should collaborate with http://drupal.org/project/twitter instead of writing a new module.