Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration error [Laravel 8.8, pagebuilder 0.24] #146

Open
promanapeople opened this issue Mar 9, 2023 · 3 comments
Open

Migration error [Laravel 8.8, pagebuilder 0.24] #146

promanapeople opened this issue Mar 9, 2023 · 3 comments

Comments

@promanapeople
Copy link

`composer require hansschouten/laravel-pagebuilder //ok
php artisan vendor:publish --provider="HansSchouten\LaravelPageBuilder\ServiceProvider" --tag=config //ok
php artisan migrate

PDOException

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pb.pagebuilder__settings' doesn't exist

at D:\www\pb\vendor\hansschouten\phpagebuilder\src\Core\DB.php:65
61▕ $stmt = $this->pdo->prepare("SELECT {$columns} FROM {$table}");
62▕ } else {
63▕ $stmt = $this->pdo->prepare("SELECT * FROM {$table}");
66▕ return $stmt->fetchAll();
67▕ }
68▕
69▕ /**

1 D:\www\pb\vendor\hansschouten\phpagebuilder\src\Core\DB.php:65
PDOStatement::execute()

2 D:\www\pb\vendor\hansschouten\phpagebuilder\src\Repositories\BaseRepository.php:156
PHPageBuilder\Core\DB::all("pagebuilder__settings", "*")`

@Dennise89
Copy link

Dennise89 commented Mar 30, 2023

Any update on this topic? I've got the same error in a fresh laravel app.

EDIT: Okay I fixed it by creating two tables in the database:

create table pagebuilder__settings (
	id int NOT NULL AUTO_INCREMENT,
	settings varchar(50) UNIQUE,
	value MEDIUMTEXT,
	is_array BOOLEAN,
	created_at DATETIME,
	updated_at DATETIME, PRIMARY KEY (id)
);

create table pagebuilder__page_translations (
	id int NOT NULL AUTO_INCREMENT,
	page_id INT UNSIGNED NOT NULL,
	locale VARCHAR(50),
	title VARCHAR(255),
	route VARCHAR(255),
	created_at DATETIME,
	updated_at DATETIME,
	PRIMARY KEY (id)
);

After that just run php artisan migrate:fresh(). Only use this if you have nothing of value in your database ofcourse!!

@irvine48
Copy link

once php artisan vendor:publish, remove the database prefix in cofig file to complete the config:cache.
i found might be database migration run before config file read causing issue to this command broken.

@neetkiss
Copy link

neetkiss commented Sep 17, 2023

public function all(string $table, $columns = '*') { $this->checkAndCreateTable($table); if (is_array($columns)) { foreach ($columns as &$column) { $column = preg_replace('/[^a-zA-Z_]*/', '', $column); } $columns = implode(',', $columns); $stmt = $this->pdo->prepare("SELECT {$columns} FROM {$table}"); } else { $stmt = $this->pdo->prepare("SELECT * FROM {$table}"); } $stmt->execute() return $stmt->fetchAll(); }

`public function checkAndCreateTable(string $tableName)
{
    $tableExists = $this->pdo->query("SHOW TABLES LIKE '{$tableName}'")->rowCount() > 0;
    if (!$tableExists) {
        // Tablo yok, oluştur
        $createQuery = "CREATE TABLE {$tableName} (
        id INT AUTO_INCREMENT PRIMARY KEY,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    )";

        $this->pdo->exec($createQuery);
        return true;
    }

    return true;
}`

line 54 in phpagebuilder/src/Core/DB.php
I will try to solve the errors on the project, this will do the trick until then.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants