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

Error with the request /upload/files/:id in MySQL #1037

Closed
omar1989omb opened this issue Apr 25, 2018 · 2 comments
Closed

Error with the request /upload/files/:id in MySQL #1037

omar1989omb opened this issue Apr 25, 2018 · 2 comments
Assignees
Labels
good first issue Good for newcomers issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around

Comments

@omar1989omb
Copy link

Informations

  • Node.js: 9.11.1
  • npm: 5.8.0
  • Strapi: 3.0.0-alpha.12.0.1
  • Database: MySQL
  • Operating system: Ubuntu 17.10

What is the current behavior?

Using the request /upload /files/:id with the GET or DELETE methods, the console displays the error:

[2018-04-25T17:46:54.220Z] error select upload_file.* from upload_filewhereupload_file._id= '_2' limit 1 - ER_BAD_FIELD_ERROR: Unknown column 'upload_file._id' in'where clause'

Steps to reproduce the problem

Using the request /upload /files/:id with MySQL and the GET or DELETE methods.

http://localhost:1337/upload/files/2 (GET or DELETE)
It shows error 500 and in the console the previous message.

Suggested solutions

In the file "/plugins/upload/config/functions/bootstrap.js" the column is called id, not _id:

CREATE TABLE ${quote}${Model.tableName || Model.collectionName}${quote} (
    id ${Model.client === 'pg' ? 'SERIAL' : 'INT AUTO_INCREMENT'} NOT NULL PRIMARY KEY,
    name text,
    hash text,
    ext text,
    mime text,
    size text,
    url text,
    provider text,
    updated_at ${Model.client === 'pg' ? 'timestamp with time zone' : 'timestamp'},
    created_at ${Model.client === 'pg' ? 'timestamp with time zone' : 'timestamp'}
  );

I have modified the file "/plugins/upload/services/Upload.js":

Lines (92-94)

 fetch: (params) => {
    return strapi.query('file', 'upload').findOne(_.pick(params, ['_id', 'id']));
  },

by:

  fetch: (params) => {
    return strapi.query('file', 'upload').findOne(_.pick(params, 'id'));
  },

Now it works fine with MySQL

@lauriejim lauriejim self-assigned this Apr 26, 2018
@lauriejim lauriejim added issue: bug Issue reporting a bug good first issue Good for newcomers labels Apr 26, 2018
@lauriejim
Copy link
Contributor

Hello @omar1989omb You are in a good way to fix it and submit a PR.

Actually your update will broke mongoose applications. You have to investigate in bookshelf queries I think instead of services

@lauriejim lauriejim added the severity: medium If it breaks the basic use of the product but can be worked around label May 11, 2018
@lauriejim
Copy link
Contributor

I think it's the same issue of #1135 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around
Projects
None yet
Development

No branches or pull requests

2 participants