• After a fresh installation and activation of learnpress plugin (latest version 4.1.3.1) not all database tables will be created in database! Because of that I got an error (error 402) while ordering a course, because the database tables learnpress_order_itemmeta and learnpress_order_items (among others) were missing.

    After a couple of hours code research I found the mistake in wp-content/plugins/learnpress/inc/class-lp-install.php where the CREATE TABLE IF NOT EXISTS statements are defined in function _get_schema(). They will be passed to the function dbDelta() in wp-admin/includes/upgrade.php for creating the db tables. The function dbDelta() is very sensitive to the given CREATE TABLE statements and can not process CREATE TABLE IF NOT EXISTS statements as they are defined! Because of that the function extracts the table name “IF” (the word after CREATE TABLE) but not the real table name for every CREATE sql statement which is used as a hash key for storing the sql statement for the table. This leads to create only one more table every time the function dbDelta() is called with database tables not created yet.

    Another issue with the function dbDelta() is that PRIMARY KEY must be followed by two spaces (as I found in some forums) and you can not use FOREIGN KEYS. Oh my god what a bad function provided by wordpress! After deleting “IF NOT EXISTS” in the CREATE TABLE statements the tables will be created flawless.

    I hope the developer of learnpress will fix this soon and will test the code for installing a fresh learnpress plugin in future?

    Please tell me if I am right with the description above?

    Thanx!

    • This topic was modified 4 years, 8 months ago by wptheek.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support brianvu-tp

    (@briantp)

    Hi,

    Thank you so much for your feedback, We already know about this issue but still haven’t fixed it, we are looking for solutions to resolve it. Have a nice day!

    Thanks

    • This reply was modified 4 years, 8 months ago by brianvu-tp.
    Thread Starter wptheek

    (@wptheek)

    Hi,

    the solution is to remove the “IF NOT EXISTS” in the CREATE TABLE statements as I already wrote. Please fix this soon as all Learnpress installation all over the world fail for now!

    By the way: The dbDelta() function would then alter an already existing table to the latest create table statement and you would not need the extra database upgrade function anymore. Right?

    • This reply was modified 4 years, 8 months ago by wptheek.
    Plugin Support brianvu-tp

    (@briantp)

    We try it but give an error MySQL, If we change it, it will fail in case the created table is recreated or the WordPress error system will report as the table exists.

    Great, I am having this trouble too. Thank you for this great plugin, good lucky

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Missing learnpress database tables after fresh installation’ is closed to new replies.