1

私はこのエンティティを持っています:

    $schema['apiuser'] = array(
        'description' => 'The base table for api_user.',
        'fields' => array(
            'apiuser_id' => array(
                'description' => 'The primary identifier for an artwork.',
                'type' => 'serial',
                'unsigned' => TRUE,
                'not null' => TRUE,
            ),
            'public_key' => array(
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
                'description' => "Foreign key: {file_managed}.fid of user's picture.",
            )           
        ),
        'unique keys' => array(
            'id' => array('apiuser_id')
        ),
        'primary key' => array('apiuser_id'),
        );

後で新しいフィールドを追加しました:

,
            $schema['apiuser'] = array(
    'description' => 'The base table for api_user.',
    'fields' => array(
        'apiuser_id' => array(
            'description' => 'The primary identifier for an artwork.',
            'type' => 'serial',
            'unsigned' => TRUE,
            'not null' => TRUE,
        ),
        'public_key' => array(
            'type' => 'int',
            'not null' => TRUE,
            'default' => 0,
            'description' => "Foreign key: {file_managed}.fid of user's picture.",
        ),
        'user_id' => array(
            'description' => 'The primary identifier for an artwork.',
            'type' => 'int',
            'not null' => TRUE,
        )

    ),
    'unique keys' => array(
        'id' => array('apiuser_id')
    ),
    'primary key' => array('apiuser_id'),
    );

Drupal はそれぞれのテーブルを mysql に変更しないので、手動で変更しました。しかし、エンティティを保存しようとすると、新しいフィールドが入力されません。devel モジュールをインストールし、'drush cc all' を使用してキャッシュをクリアし、モジュールを非アクティブ化およびアクティブ化しましたが、それでも機能しません

4

1 に答える 1

0

これが更新スクリプトの目的です。update_N関数を記述します。この関数では、スキーマオブジェクトを使用して列を追加できます

function your_module_update_7001($sandbox) {
  // do some checking (i.e. if already exists, etc)
  // get $schema from wherever you defined it for hook_schema...
  $spec = $schema['fields']['user_id'];
  Database::getConnection()->schema()->addField('apiuser', 'user_id', $spec);
}

次に実行するhttp://yoursite.com/update.phpと、drupalはそれに応じてテーブルを変更します。

于 2012-09-03T16:45:38.170 に答える