I'm setting up a database migration. For now, I'm using the ssh tunnel to access the remote databse.

Here is the configuration in the Migration class:

Database::addConnectionInfo('for_migration', 'default', array(
  'driver' => 'mysql',
  'database' => 'database',
  'username' => 'user',
  'password' => '****',
  'host' => '',
  'port' => '1000',
  'prefix' => '',

// Conect to the remote $databases
$query = Database::getConnection('default', 'for_migration')
    ->select('Content', 'ct');

// Better descriptions for wineid and name; best_vintages is added in prepareRow()
$source_fields = array(
  'id' => t('article ID'),
  'contenido' => t('Contenido'),

// Create a MigrateSource object, which manages retrieving the input data.
// Tell the source class not to try to join the map table.
$this->source = new MigrateSourceSQL($query,
    array('map_joinable' => FALSE)

$this->destination = new MigrateDestinationNode('article');

$this->map = new MigrateSQLMap($this->machineName,
        'id' => array('type' => 'int',
                           'not null' => TRUE,
                           'description' => 'Article ID',
                           'alias' => 'id',

// @todo Mapped fields
$this->addFieldMapping('body', 'content');

When I try to access the migration UI page the count of items is correct, but I get and error when I try to load the task page to visualize the mappings and elements.

DOException: 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 'FROM Content ct LIMIT 1 OFFSET 0' at line 1: SELECT FROM {Content} ct LIMIT 1 OFFSET 0; Array ( ) in MigrateSourceSQL->fields() (line 211 of /Users/brightsitesSM/Sites/devdesktop/independentpoc-dev/docroot/sites/all/modules/migrate/plugins/sources/sql.inc).

Probably there is something missing in the code as the SELECT in the SQL query is empty.

Here are the screenshots of the migration page: Migration page

... and the task page error: Task page

  • The problem is that there are no fields in the SQL query (SELECT FROM is invalid SQL). Does that shed any light? – Clive Jan 23 '15 at 16:14
  • also the select is for ->select('Contenido', 'ct'); but your PDO error says SELECT FROM Content ... you need to check your table names and field names your using. – tenken Jan 23 '15 at 17:07
  • I think I had a similar issue with db_select. try to add ->fields('ct') to your select. – sareed Jan 23 '15 at 19:46
  • Thanks. Yes, that's the issue I'll try adding fields to the db_select as @sareed sudgested. I think there is the issue. – Miguelos Jan 24 '15 at 20:28
  • @tenken sorry, that's a typo. The table name is ok. – Miguelos Jan 26 '15 at 13:44

The problem with the code is the connection to the database. There aren't fields in the select.

SELECT FROM {Content} ct

To solve that one of the solutions is adding ->fields('ct'); to the database connection. This will select all the fields from the table ct:

SELECT ct.* FROM {Content} ct
|improve this answer|||||
  • Information about how fields function works here. – Miguelos Feb 2 '15 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.