Welcome Guest, Not a member yet? Register   Sign In
ERROR: DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci' at line 9
#1

Problem
Trying to create some migrations as I am learning CI and keep getting the following error: 
---------
Running all new migrations...

[CodeIgniter\Database\Exceptions\DatabaseException]

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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci' at line 9

at SYSTEMPATH/Database/BaseConnection.php:646

------------------
I have installed CI4 on a PopOS linux machine
mysql version: 8.0.34-0ubuntu0.22.04.1
PHP version: 8.1.2-1ubuntu2.14
I am a Codeigniter newbie and although I have coded for years in the past and I have been a DBA in the past my mysql is only fine. 
Background
- Learning how to do migrations
- Have setup the DB connection in App/config/Database.php as follows: 
    public array $default = [
        'DSN'          => '',
        'hostname'    => 'localhost',
        'username'    => 'xxxxx',
        'password'    => 'xxxxx',
        'database'    => 'ci4blog_db',
        'DBDriver'    => 'MySQLi',
        'DBPrefix'    => '',
        'pConnect'    => false,
        'DBDebug'      => true,
        'charset'      => 'utf8mb4',
        'DBCollat'    => 'utf8mb4_0900_ai_ci',
        'swapPre'      => '',
        'encrypt'      => false,
        'compress'    => false,
        'strictOn'    => false,
        'failover'    => [],
        'port'        => 3306,
        'numberNative' => false,
    ];

I have checked that the Character set in the DB are correct by doing the following: 
SELECT @@character_set_database, @@collation_database
--------------

+--------------------------+----------------------+
| @@character_set_database | @@collation_database |
+--------------------------+----------------------+
| utf8mb4                  | utf8mb4_0900_ai_ci  |
+--------------------------+----------------------+
1 row in set (0.00 sec)

From what I can see I have the config matching the DB but yet, I still get the error above  
I have tried different Character set and collation combinations, and I always get the same error
I could avoid using migrations by writing all my sql myself but feel I would like to understand the power of the migrations before doing that. 
Any ideas welcome. 

Thanks you
Reply
#2

Check the SQL statement that causes the error.
Reply
#3

I can say that I use the utf8mb4 and utf8mb4_unicode_ci without Error on Windows PHP 8.2.4.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

I believe the following link can help you: https://tecadmin.net/resolved-unknown-co...SnippetTab
I also use a language of Latin origin and use the option "utf8mb4.swedish.ci" which is accent insensitive and case insensitive.
If plan A fails, relax... the alphabet is 26 letters
Reply
#5

(10-03-2023, 04:45 PM)kenjis Wrote: Check the SQL statement that causes the error.
Thank you for the suggestion. I have resolved the issue. Here is information for other people who may come across this. 

Firstly the migrate action was not giving me the whole SQL, so it was hard to see what was wrong. 

I used the error message to find where the exception was being raised and put and echo $query in. That then gave me the whole query. 

That still did not help TBH. So I removed the characterset and collate lines and looked at the pure SQL. Turns out that the KEY definition was incorrect.  I then went back to my migration and saw that a ' was missing at the end of the field definition. 

Added that and Bingo, all was working again. 

Thank you everyone who took time to answer. Much appreciated.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB