ShahiLanding

Database and Migration Issues

This guide helps you troubleshoot database-related problems, migration errors, and data integrity issues with ShahiLandin.

Database Tables Missing

Symptom

Plugin activated but features don’t work, or errors mentioning missing tables.

Solutions

Problem 1: Tables Not Created During Activation

Error Message:
`
Table ‘wpshahilandinanalytics’ doesn’t exist
`

Solution 1 – Reactivate Plugin:

  1. Go to Plugins page
  2. Deactivate ShahiLandin
  3. Wait 5 seconds
  4. Activate ShahiLandin again
  5. Check if tables were created
  6. Solution 2 – Check Database Permissions:

  7. Access phpMyAdmin
  8. Click on your WordPress database
  9. Check if user has CREATE TABLE permission
  10. Grant permissions if missing (contact host if needed)
  11. Solution 3 – Run Manual Migration:

  12. Download run-migrations.php file from plugin folder
  13. Upload to WordPress root directory (same level as wp-config.php)
  14. Visit https://yoursite.com/run-migrations.php in browser
  15. Follow on-screen instructions
  16. Delete the file after completion (security)
  17. Solution 4 – Use WP-CLI:
    `bash
    wp shahilandin migrate
    `

    Problem 2: Verify Tables Exist

    Check if ShahiLandin tables exist in database:

    Via phpMyAdmin:

  18. Log into phpMyAdmin
  19. Select your WordPress database
  20. Look for these tables:
  21. wpshahilandinanalytics
    wpshahilandinexperiments
    wp_posts (standard WordPress table, used for landing pages)
    wp_postmeta (standard WordPress table, used for landing page meta)

    Via WP-CLI:
    `bash

    List all tables

    wp db tables –scope=all

    Check specific table

    wp db query “DESCRIBE wpshahilandinanalytics”
    `

    If tables are missing, proceed with manual migration above.

    Migration Errors

    Symptom

    Errors during plugin update or database migration.

    Solutions

    Problem 1: Migration Script Timeout

    Error Message:
    `
    Maximum execution time of 30 seconds exceeded
    `

    Solution:

  22. Increase PHP execution time in .htaccess:
  23. `apache
    phpvalue maxexecution_time 300
    phpvalue maxinput_time 300
    `

  24. Or in wp-config.php:
  25. `php
    settimelimit(300);
    `

  26. Run migration again
  27. Problem 2: Migration Already Running

    Error Message:
    `
    Migration already in progress
    `

    Solution:

  28. Previous migration may have crashed
  29. Clear migration lock:
  30. `bash
    wp option delete shahilandinmigrationlock
    `

  31. Or via phpMyAdmin:
  32. `sql
    DELETE FROM wpoptions WHERE optionname = ‘shahilandinmigrationlock’;
    `

  33. Retry migration
  34. Problem 3: Database Schema Mismatch

    Symptom: Plugin expects different table structure than what exists.

    Solution:

  35. Check current schema version:
  36. `bash
    wp option get shahilandindbversion
    `

  37. Compare with plugin version
  38. Force re-run migrations:
  39. `bash
    wp shahilandin migrate –force
    `

  40. Or reset and rebuild:
  41. `sql
    — CAUTION: This deletes ALL ShahiLandin data
    DROP TABLE IF EXISTS wpshahilandinanalytics;
    DROP TABLE IF EXISTS wpshahilandinexperiments;
    DELETE FROM wpoptions WHERE optionname LIKE ‘shahilandin_%’;
    `
    Then reactivate plugin to recreate tables.

    Problem 4: Foreign Key Constraints

    Error Message:
    `
    Cannot add foreign key constraint
    `

    Solution:

  42. Usually caused by inconsistent storage engines
  43. Check table engines:
  44. `sql
    SELECT TABLE_NAME, ENGINE
    FROM information_schema.TABLES
    WHERE TABLESCHEMA = ‘yourdatabase_name’
    AND TABLENAME LIKE ‘wpshahilandin%’;
    `

  45. Ensure all tables use InnoDB:
  46. `sql
    ALTER TABLE wpshahilandinanalytics ENGINE=InnoDB;
    ALTER TABLE wpshahilandinexperiments ENGINE=InnoDB;
    `

    Data Loss Issues

    Symptom

    Landing pages, analytics data, or experiments disappeared.

    Solutions

    Problem 1: Landing Pages Deleted

    Solution 1 – Check Trash:

  47. Go to Landing Pages
  48. Click Trash link at top
  49. Select pages to restore
  50. Click Restore
  51. Solution 2 – Check Database:
    `sql
    — Find trashed landing pages
    SELECT ID, posttitle, poststatus
    FROM wp_posts
    WHERE posttype = ‘shahilanding’
    AND post_status = ‘trash’;

    — Restore from trash
    UPDATE wp_posts
    SET post_status = ‘publish’
    WHERE ID = ;
    `

    Solution 3 – Restore from Backup:

  52. If you have database backup, restore it
  53. Use tools like UpdraftPlus or BackWPup
  54. Or contact hosting provider for backup restoration
  55. Problem 2: Analytics Data Missing

    Symptom: Historical analytics data disappeared.

    Solution:

  56. Check if data retention policy deleted old data:
  57. – Settings → Analytics → Data Retention Period

  58. Query database to verify:
  59. `sql
    — Check if any analytics data exists
    SELECT COUNT(*) FROM wpshahilandinanalytics;

    — Check date range of data
    SELECT MIN(createdat) as oldest, MAX(createdat) as newest
    FROM wpshahilandinanalytics;
    `

  60. If truly deleted:
  61. – Check database backups
    – Data may be in exported CSV/JSON files
    – Contact support with backup if available

    Problem 3: Experiments Lost

    Solution:
    `sql
    — Check experiments table
    SELECT * FROM wpshahilandinexperiments;

    — Check if experiments are “soft deleted”
    SELECT * FROM wpshahilandinexperiments WHERE deleted_at IS NOT NULL;

    — Restore soft-deleted experiment
    UPDATE wpshahilandinexperiments
    SET deleted_at = NULL
    WHERE id = ;
    `

    Database Corruption

    Symptom

    Errors indicating corrupted tables or data inconsistencies.

    Solutions

    Problem 1: Table Crashed

    Error Message:
    `
    Table ‘wpshahilandinanalytics’ is marked as crashed and should be repaired
    `

    Solution 1 – Automatic Repair:

  62. Add to wp-config.php:
  63. `php
    define(‘WPALLOWREPAIR’, true);
    `

  64. Visit: https://yoursite.com/wp-admin/maint/repair.php
  65. Click Repair Database
  66. Remove the define line after repair
  67. Solution 2 – Manual Repair via phpMyAdmin:

  68. Go to phpMyAdmin
  69. Select your database
  70. Check corrupted table
  71. Click Operations tab
  72. Click Repair table
  73. Solution 3 – WP-CLI:
    `bash
    wp db repair
    `

    Problem 2: Orphaned Meta Data

    Symptom: Database bloated with meta data for deleted posts.

    Solution:
    Clean up orphaned data:
    `sql
    — Count orphaned meta
    SELECT COUNT(*) FROM wp_postmeta
    WHERE postid NOT IN (SELECT ID FROM wpposts);

    — Delete orphaned meta (CAUTION: Backup first)
    DELETE FROM wp_postmeta
    WHERE postid NOT IN (SELECT ID FROM wpposts);

    — Optimize table after cleanup
    OPTIMIZE TABLE wp_postmeta;
    `

    Problem 3: Duplicate Entries

    Symptom: Duplicate analytics events or experiments.

    Solution:
    `sql
    — Find duplicate analytics entries
    SELECT postid, createdat, COUNT(*) as duplicates
    FROM wpshahilandinanalytics
    GROUP BY postid, createdat
    HAVING COUNT(*) > 1;

    — Remove duplicates (keeps one, deletes rest)
    DELETE t1 FROM wpshahilandinanalytics t1
    INNER JOIN wpshahilandinanalytics t2
    WHERE t1.id > t2.id
    AND t1.postid = t2.postid
    AND t1.createdat = t2.createdat;
    `

    Import/Export Issues

    Symptom

    Cannot import or export landing pages or data.

    Solutions

    Problem 1: Export Timeout

    Symptom: Export process hangs or times out with large datasets.

    Solution 1 – Export in Batches:
    `bash

    Export specific date range

    wp shahilandin export –from=2024-01-01 –to=2024-03-31 –format=csv > Q1-2024.csv

    Export specific landing page

    wp shahilandin export –post-id=123 –format=json > landing-123.json
    `

    Solution 2 – Increase PHP Limits:
    `apache

    In .htaccess

    phpvalue memorylimit 512M
    phpvalue maxexecution_time 300
    `

    Solution 3 – Direct Database Export:
    `bash

    Export via mysqldump

    mysqldump -u username -p databasename wpshahilandinanalytics > analyticsbackup.sql
    `

    Problem 2: Import Fails

    Symptom: Importing landing pages or data results in errors.

    Solution 1 – Check File Format:

  74. Ensure import file is valid JSON or CSV
  75. Validate JSON: https://jsonlint.com/
  76. Check CSV has proper headers
  77. Solution 2 – Check File Size:

  78. Split large files into smaller chunks
  79. Import in batches
  80. Solution 3 – Fix Encoding Issues:
    `bash

    Convert file to UTF-8

    iconv -f ISO-8859-1 -t UTF-8 import.csv > import-utf8.csv
    `

    Solution 4 – Import via WP-CLI:
    `bash

    Import landing pages

    wp shahilandin import landing-pages.json

    Import with dry-run first

    wp shahilandin import landing-pages.json –dry-run
    `

    Performance Issues

    Symptom

    Database queries slow, admin dashboard takes long to load.

    Solutions

    Problem 1: Missing Indexes

    Solution:
    Add indexes to improve query performance:
    `sql
    — Analytics table indexes
    ALTER TABLE wpshahilandinanalytics
    ADD INDEX idxpostid (post_id);

    ALTER TABLE wpshahilandinanalytics
    ADD INDEX idxcreatedat (created_at);

    ALTER TABLE wpshahilandinanalytics
    ADD INDEX idx_goal (goal);

    ALTER TABLE wpshahilandinanalytics
    ADD INDEX idxexperimentid (experiment_id);

    — Composite index for common queries
    ALTER TABLE wpshahilandinanalytics
    ADD INDEX idxpostcreated (postid, createdat);
    `

    Problem 2: Large Analytics Table

    Symptom: wpshahilandinanalytics table has millions of rows.

    Solution 1 – Archive Old Data:
    `sql
    — Export old data before deletion
    SELECT * FROM wpshahilandinanalytics
    WHERE createdat < DATESUB(NOW(), INTERVAL 6 MONTH)
    INTO OUTFILE ‘/tmp/analytics_archive.csv’;

    — Delete old data
    DELETE FROM wpshahilandinanalytics
    WHERE createdat < DATESUB(NOW(), INTERVAL 6 MONTH);

    — Optimize table
    OPTIMIZE TABLE wpshahilandinanalytics;
    `

    Solution 2 – Enable Auto-Cleanup:

  81. Go to Settings → Analytics
  82. Set Data Retention Period: 90 days (or as needed)
  83. Old data automatically deleted daily
  84. Solution 3 – Partition Table (Advanced):
    `sql
    — Partition by date for better performance
    ALTER TABLE wpshahilandinanalytics
    PARTITION BY RANGE (YEAR(created_at)) (
    PARTITION p2023 VALUES LESS THAN (2024),
    PARTITION p2024 VALUES LESS THAN (2025),
    PARTITION p2025 VALUES LESS THAN (2026),
    PARTITION pmax VALUES LESS THAN MAXVALUE
    );
    `

    Problem 3: Slow Query Log

    Solution:
    Identify slow queries:
    `sql
    — Enable slow query log (if not already)
    SET GLOBAL slowquerylog = ‘ON’;
    SET GLOBAL longquerytime = 2; — Log queries over 2 seconds

    — Check slow queries
    SHOW GLOBAL STATUS LIKE ‘Slow_queries’;
    `

    Review slow query log and optimize identified queries.

    Character Encoding Issues

    Symptom

    Special characters display as �, or foreign language text garbled.

    Solutions

    Problem 1: Wrong Database Charset

    Solution:
    Convert database to UTF-8:
    `sql
    — Check current charset
    SHOW TABLE STATUS WHERE Name = ‘wpshahilandinanalytics’;

    — Convert to UTF-8
    ALTER TABLE wpshahilandinanalytics
    CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4unicodeci;

    ALTER TABLE wpshahilandinexperiments
    CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4unicodeci;
    `

    Problem 2: wp-config.php Charset Setting

    Solution:
    Ensure wp-config.php has correct charset:
    `php
    define(‘DB_CHARSET’, ‘utf8mb4’);
    define(‘DBCOLLATE’, ‘utf8mb4unicode_ci’);
    `

    Problem 3: Existing Data with Wrong Encoding

    Solution:
    Fix existing data:
    `sql
    — Update specific field
    UPDATE wp_postmeta
    SET metavalue = CONVERT(CAST(CONVERT(metavalue USING latin1) AS BINARY) USING utf8mb4)
    WHERE metakey = ‘shahilandin_html’;
    `

    Multisite Database Issues

    Symptom

    Issues specific to WordPress Multisite installations.

    Solutions

    Problem 1: Tables on Wrong Blog

    Symptom: Plugin activated but tables missing on subsite.

    Solution:
    In multisite, each blog has separate tables:

    • Blog 1: wpshahilandinanalytics
    • Blog 2: wp2shahilandin_analytics
    • Blog 3: wp3shahilandin_analytics
    • Network activate plugin to create tables for all sites:

    • Go to Network Admin → Plugins
    • Click Network Activate on ShahiLandin
    • Problem 2: Shared Analytics Across Network

      Symptom: Want to aggregate analytics from all subsites.

      Solution:
      Create custom query across all blog tables:
      `sql
      — Get analytics from all sites
      SELECT * FROM wpshahilandinanalytics
      UNION ALL
      SELECT * FROM wp2shahilandin_analytics
      UNION ALL
      SELECT * FROM wp3shahilandin_analytics;
      `

      Or use WP-CLI to iterate:
      `bash

      Export analytics from all sites

      wp site list –field=url | xargs -I {} wp –url={} shahilandin export
      `

      Backup and Restore

      Creating Backups

      Full Database Backup:

      `bash

      Backup entire database

      mysqldump -u username -p databasename > fullbackup.sql

      Backup only ShahiLandin data

      mysqldump -u username -p database_name \
      wpshahilandinanalytics \
      wpshahilandinexperiments \
      wp_posts \
      wp_postmeta \
      > shahilandin_backup.sql
      `

      Table-Specific Backup:

      `bash

      Backup analytics only

      mysqldump -u username -p databasename wpshahilandinanalytics > analyticsbackup.sql

      Backup with compression

      mysqldump -u username -p database_name | gzip > backup.sql.gz
      `

      Using WP-CLI:

      `bash

      Export database

      wp db export shahilandin_backup.sql

      Export specific tables

      wp db export shahilandinbackup.sql –tables=wpshahilandinanalytics,wpshahilandin_experiments
      `

      Restoring Backups

      Full Restore:

      `bash

      Restore from SQL file

      mysql -u username -p databasename < fullbackup.sql

      Or via WP-CLI

      wp db import full_backup.sql
      `

      Selective Restore:

      `sql
      — Restore only analytics data
      SOURCE analytics_backup.sql;

      — Or import specific table
      mysql -u username -p databasename < analyticsbackup.sql
      `

      Database Optimization

      Regular Maintenance Tasks

      Daily Tasks:

      `sql
      — Clean up old analytics (if retention enabled)
      DELETE FROM wpshahilandinanalytics
      WHERE createdat < DATESUB(NOW(), INTERVAL 90 DAY);

      — Clean up auto-drafts
      DELETE FROM wp_posts
      WHERE posttype = ‘shahilanding’
      AND post_status = ‘auto-draft’
      AND postmodified < DATESUB(NOW(), INTERVAL 7 DAY);
      `

      Weekly Tasks:

      `sql
      — Optimize tables
      OPTIMIZE TABLE wpshahilandinanalytics;
      OPTIMIZE TABLE wpshahilandinexperiments;
      OPTIMIZE TABLE wp_posts;
      OPTIMIZE TABLE wp_postmeta;

      — Analyze tables for query optimization
      ANALYZE TABLE wpshahilandinanalytics;
      ANALYZE TABLE wpshahilandinexperiments;
      `

      Monthly Tasks:

      `sql
      — Check for corrupted tables
      CHECK TABLE wpshahilandinanalytics;
      CHECK TABLE wpshahilandinexperiments;

      — Repair if needed
      REPAIR TABLE wpshahilandinanalytics;
      `

      Automated Maintenance via WP-CLI

      Create a cron job:
      `bash

      Daily optimization script

      0 3 * wp db optimize

      Weekly cleanup script

      0 2 0 wp shahilandin cleanup –days=90
      `

      Getting Help

      If database issues persist:

    • Backup first before any destructive operations
    • Collect information:
    • – Database size: wp db size
      – Table status: wp db tables --scope=all
      – Database version: wp db cli version
      – Error messages from debug.log

    • Export schema:
    • `bash
      mysqldump -u username -p –no-data database_name > schema.sql
      `

    • Check table integrity:
    • `sql
      CHECK TABLE wpshahilandinanalytics;
      CHECK TABLE wpshahilandinexperiments;
      `

    • Contact support with:
    • – Database error messages
      – Table structure (schema)
      – Steps to reproduce issue
      – Backup of affected data (if possible)

      Related Articles:

    • Installation and Activation Issues
    • Performance Issues
    • Cache and Plugin Conflicts

Share this article

Was this article helpful?

Help us improve our documentation

Still need help?

Our support team is ready to assist you with personalized guidance for your workspace.

Submit a support ticket