0
votes

I'm trying to create new DB, which is created successfully, and some tables in that DB, table is not created. Whats wrong with this query? It says:

QueryException in Connection.php line 770: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE TABLE activities ( id int(10) UNSIGNED NOT NULL, ' at line 3 (SQL: CREATE DATABASE institution_70 CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE activities ( id int(10) UNSIGNED NOT NULL, name varchar(150) COLLATE utf8_unicode_ci NOT NULL, created_at timestamp NULL DEFAULT NULL, updated_at timestamp NULL DEFAULT NULL, deleted_at timestamp NULL DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; )

DB::connection('rc')->statement("
    CREATE DATABASE institution_$institutionId CHARACTER SET utf8 COLLATE utf8_general_ci;

    CREATE TABLE `activities` (
      `id` int(10) UNSIGNED NOT NULL,
      `name` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
      `created_at` timestamp NULL DEFAULT NULL,
      `updated_at` timestamp NULL DEFAULT NULL,
      `deleted_at` timestamp NULL DEFAULT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    ");
1

1 Answers

0
votes

remove‍‍ NULL after timestamp

   CREATE TABLE `activities` (
      `id` int(10) UNSIGNED NOT NULL,
      `name` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
      `created_at` timestamp DEFAULT NULL,
      `updated_at` timestamp DEFAULT NULL,
      `deleted_at` timestamp DEFAULT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;