thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.77k stars 2.67k forks source link

clean install of laravel8 + voyager fails with error: "no such table: users (SQL: alter table "users" add column "avatar" varchar default 'users/default.png')"" #5256

Closed huna02 closed 3 years ago

huna02 commented 3 years ago

## Version information

 - Laravel: v8.32.1
 - Voyager: v1.x-dev e9160b7
 - PHP: 7.4.16
 - Database: sqlite 3.34.1

## Description clean install of laravel8 + voyager fails with error

"SQLSTATE[HY000]: General error: 1 no such table: users (SQL: alter table "users" add column "avatar" varchar default 'users/default.png')"

## Steps To Reproduce

cd /tmp

rm -rf test.app
rm -f  voyager.db

composer create-project laravel/laravel test.app
cd  test.app
composer require tcg/voyager
composer show | egrep "laravel/framework|tcg/voyager"
    laravel/framework                  v8.32.1         The Laravel Framework.
    tcg/voyager                        1.x-dev e9160b7 A Laravel Admin Package for The Control Group to make your life eas...

touch    /tmp/voyager.db

edit .env
+   DB_CONNECTION='sqlite'
+   DB_DATABASE='/tmp/voyager.db'

php artisan voyager:install
    Publishing the Voyager assets, database, and config files
    Copied Directory [/vendor/tcg/voyager/publishable/database/seeds] To [/database/seeds]
    Publishing complete.
    Migrating the database tables into your application
    Migration table created successfully.
    Migrating: 2016_01_01_000000_add_voyager_user_fields

    Illuminate\Database\QueryException

    SQLSTATE[HY000]: General error: 1 no such table: users (SQL: alter table "users" add column "avatar" varchar default 'users/default.png')

    at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
        674▕         // If an exception occurs when attempting to run a query, we'll format the error
        675▕         // message to include the bindings with SQL, which will make this exception a
        676▕         // lot more helpful to the developer instead of just the database's errors.
        677▕         catch (Exception $e) {
    ➜ 678▕             throw new QueryException(
        679▕                 $query, $this->prepareBindings($bindings), $e
        680▕             );
        681▕         }
        682▕

        +45 vendor frames
    46  artisan:37
        Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
MrCrayon commented 3 years ago

I have no idea why but your problem is not with Voyager, for some reason Laravel users migration is not running so Voyager migration does not work.

I did the same exact steps and it works just fine.

composer create-project laravel/laravel test.app
cd  test.app
composer require tcg/voyager
touch database/database.sqlite
vim .env
php artisan voyager:install

Successfully installed Voyager! Enjoy
huna02 commented 3 years ago

hm.

tried same on a couple of different machines; same fail.

also an issue if I 1st throw jetstream into the mix

composer create-project laravel/laravel test.app
cd test.app

composer require laravel/jetstream
php artisan jetstream:install livewire --teams
npm install
npm run dev
edit .env
    -> DB setup

php artisan migrate

composer require tcg/voyager
    Using version ^1.4 for tcg/voyager
    ./composer.json has been updated
    Running composer update tcg/voyager
    Loading composer repositories with package information
    Updating dependencies
    Lock file operations: 20 installs, 0 updates, 0 removals
    - Locking arrilot/laravel-widgets (3.13.1)
    - Locking composer/ca-bundle (1.2.9)
    - Locking composer/composer (2.0.11)
    - Locking composer/semver (3.2.4)
    - Locking composer/spdx-licenses (1.5.5)
    - Locking composer/xdebug-handler (1.4.5)
    - Locking doctrine/cache (1.10.2)
    - Locking doctrine/dbal (2.12.1)
    - Locking doctrine/event-manager (1.1.1)
    - Locking intervention/image (2.5.1)
    - Locking justinrainbow/json-schema (5.2.10)
    - Locking larapack/doctrine-support (v0.1.9)
    - Locking larapack/hooks (v1.0.12)
    - Locking larapack/voyager-hooks (v1.2.3)
    - Locking laravel/ui (v3.2.0)
    - Locking react/promise (v2.8.0)
    - Locking seld/jsonlint (1.8.3)
    - Locking seld/phar-utils (1.1.1)
    - Locking symfony/filesystem (v5.2.4)
    - Locking tcg/voyager (1.x-dev e9160b7)
    Writing lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 20 installs, 0 updates, 0 removals
    - Syncing tcg/voyager (1.x-dev e9160b7) into cache
    - Installing composer/ca-bundle (1.2.9): Extracting archive
    - Installing composer/semver (3.2.4): Extracting archive
    - Installing composer/spdx-licenses (1.5.5): Extracting archive
    - Installing composer/xdebug-handler (1.4.5): Extracting archive
    - Installing doctrine/cache (1.10.2): Extracting archive
    - Installing doctrine/event-manager (1.1.1): Extracting archive
    - Installing justinrainbow/json-schema (5.2.10): Extracting archive
    - Installing symfony/filesystem (v5.2.4): Extracting archive
    - Installing seld/phar-utils (1.1.1): Extracting archive
    - Installing seld/jsonlint (1.8.3): Extracting archive
    - Installing react/promise (v2.8.0): Extracting archive
    - Installing composer/composer (2.0.11): Extracting archive
    - Installing larapack/hooks (v1.0.12): Extracting archive
    - Installing laravel/ui (v3.2.0): Extracting archive
    - Installing larapack/voyager-hooks (v1.2.3): Extracting archive
    - Installing doctrine/dbal (2.12.1): Extracting archive
    - Installing larapack/doctrine-support (v0.1.9): Extracting archive
    - Installing intervention/image (2.5.1): Extracting archive
    - Installing arrilot/laravel-widgets (3.13.1): Extracting archive
    - Installing tcg/voyager (1.x-dev e9160b7): Cloning e9160b7c10 from cache
    4 package suggestions were added by new dependencies, use `composer suggest` to see details.
    Generating optimized autoload files
    > Illuminate\Foundation\ComposerScripts::postAutoloadDump
    > @php artisan package:discover --ansi
    PHP Fatal error:  Trait 'Laravel\Sanctum\HasApiTokens' not found in /home/dev/test.app/app/Models/User.php on line 14
    PHP Fatal error:  Uncaught ErrorException: Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop' in /home/dev/test.app/vendor/symfony/error-handler/Error/FatalError.php:37
    Stack trace:
    #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Function must b...', '/home/dev/t...', 37, Array)
    #1 /home/dev/test.app/vendor/symfony/error-handler/Error/FatalError.php(37): xdebug_get_function_stack()
    #2 /home/dev/test.app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(143): Symfony\Component\ErrorHandler\Error\FatalError->__construct('Trait 'Laravel\\...', 0, Array, 0)
    #3 /home/dev/test.app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(130): Illuminate\Foundation\Bootstrap\HandleExceptions->fatalErrorFromPhpError(Array, 0)
    #4 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions in /home/dev/test.app/vendor/symfony/error-handler/Error/FatalError.php on line 37
    Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

    Installation failed, reverting ./composer.json and ./composer.lock to their original content.
MrCrayon commented 3 years ago
PHP Fatal error:  Trait 'Laravel\Sanctum\HasApiTokens' not found in /home/dev/test.app/app/Models/User.php on line 14

This is not related to Voyager.

huna02 commented 3 years ago

it only appears when attempting to require tcg/voyager.

but, ok. thx anyway.

MrCrayon commented 3 years ago

That happens when you require tcg/voyager does not mean that is voyager fault, but only that voyager install does some things that require your app to be setup properly and it looks like it's not for some reason.

Did you try to install jetstream and see if it works without installing Voyager?

huna02 commented 3 years ago

yep

laravel is OK laravel + jetstream is OK laravel + jetstream + Nova is OK laravel + jetstream + Backback is OK ... etc ... laravel + jetstream + !voyager is OK

rohankhudedev commented 3 years ago

Its not voyager issue. Looks like you are using sanctum without installing it. Try composer require laravel/sanctum

MrCrayon commented 3 years ago

@rohankhudedev laravel/sanctum should be already automatically installed with those steps. @huna02 as you can see below I tried and I cannot reproduce your problem. Both errors you are seeing are not related to Voyager even if they happen when you require voyager.

SQLSTATE[HY000]: General error: 1 no such table: users (SQL: alter table "users" add column "avatar" varchar default 'users/default.png')

Users table migration did not run for some reason

PHP Fatal error: Trait 'Laravel\Sanctum\HasApiTokens' not found in /home/dev/test.app/app/Models/User.php on line 14

Sanctum is not installed for some reason

I don't see the point of keeping this issue open as I have no way to reproduce it and it looks unrelated but if you have something new that we can connect to Voyager we can reopen it.

Tried to reproduce error with no success:

composer create-project laravel/laravel test.app ;
cd  test.app ;
composer require laravel/jetstream ;
php artisan jetstream:install livewire --teams ;
npm install ;
npm run dev ;
touch database/database.sqlite ;
vim .env ;

db configuration

php artisan migrate ;
php artisan serve ;

Working

composer require tcg/voyager ;

Package manifest generated successfully.

Still working

php artisan voyager:install --with-dummy
php artisan serve ;

Still working

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.