spatie / mailcoach-support

Questions and support for Mailcoach
https://mailcoach.app
31 stars 2 forks source link

New installed mailcoach use api have error. #263

Closed bolechen closed 3 years ago

bolechen commented 3 years ago
[2020-10-17 11:24:02] production.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'api_token' in 'where clause' (SQL: select * from `users` where `api_token` = 1|OnyQE0UUBcszeBShbJBRdot7WtkaQTpmgq1jQNOF limit 1) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'api_token' in 'where clause' (SQL: select * from `users` where `api_token` = 1|OnyQE0UUBcszeBShbJBRdot7WtkaQTpmgq1jQNOF limit 1) at /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php:671)
[stacktrace]
#0 /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php(631): Illuminate\\Database\\Connection->runQueryCallback()
#1 /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php(339): Illuminate\\Database\\Connection->run()
#2 /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2302): Illuminate\\Database\\Connection->select()
#3 /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2290): Illuminate\\Database\\Query\\Builder->runSelect()
#4 /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2785): Illuminate\\Database\\Query\\Builder->Illuminate\\Database\\Query\\{closure}()
#5 /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2291): Illuminate\\Database\\Query\\Builder->onceWithColumns()
#6 /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(547): Illuminate\\Database\\Query\\Builder->get()
#7 /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(531): Illuminate\\Database\\Eloquent\\Builder->getModels()
#8 /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(147): 

I installed new mailcoach app in my server via

composer create-project spatie/Mailcoach

After config, the ui worked all good, But when i call with api, it always return 500 error, the error log have some contents below, and a saw my mysql database table, users tables do not have the api_token column.

Where am i wrong?

bolechen commented 3 years ago

here is the debug info


Health check:

Environment: production Debug: OFF Horizon: Active Queue connection: OK Webhooks: 11 unprocessed webhooks Schedule: ran 0 minute(s) ago Default mailer: smtp Mailcoach mailer: null Campaign mailer: null Transactional mailer: null

Technical details

App directory: /home/forge/dm.nanrenwa.com User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.20 Safari/537.36 PHP version: 7.4.11 MySQL version: 5.7.26-log Laravel version: 8.10.0 Horizon version: v5.2.1@8fbe70580d653e0f5c33ed9b151f6eebc16dfbf2 laravel-mailcoach version: 3.2.3 mailcoach-ui version: 1.0.3

riasvdv commented 3 years ago

Could you check and make sure this line is set to sanctum in your project? https://github.com/spatie/Mailcoach/blob/master/config/mailcoach.php#L135

bolechen commented 3 years ago

Could you check and make sure this line is set to sanctum in your project? https://github.com/spatie/Mailcoach/blob/master/config/mailcoach.php#L135

yes have this

image
riasvdv commented 3 years ago

Which endpoint are you trying?

bolechen commented 3 years ago

Which endpoint are you trying?

i test with curl

image
bolechen commented 3 years ago

the server error log is

 Oct 19 15:45:08 taobao [2020-10-19 07:45:08] production.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'api_token' in 'where clause' (SQL: select * from `users` where `api_token` = 2|R1EB2Gi6QyonWBDaUz1UcbNL0YI3wfRUZrTsANGd limit 1) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'api_token' in 'where clause' (SQL: select * from `users` where `api_token` = 2|R1EB2Gi6QyonWBDaUz1UcbNL0YI3wfRUZrTsANGd limit 1) at /home/forge/dm.nanrenwa.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php:671)
agusesetiyono commented 3 years ago

Mailcoach uses job batching under the hood. Make sure you add the required database table, as mentioned in the Laravel docs on Job batching.

try to run

php artisan queue:batches-table php artisan migrate

riasvdv commented 3 years ago

@bolechen There is a conflict with the route in routes/api.php, remove the route there and the Mailcoach API should work.