Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've just updated a site from a really old version to alpha2 and the following error shows for anonymous users:
Exception: Query tagged for file access but there is no fid. Add foreign keys to file_managed.fid in schema to fix. in _file_entity_query_file_entity_access_alter() (line 1812 of file_entity/file_entity.module).
This doesn't show for admin users.
Comments
Comment #1
Dave ReidWill probably need your help with reporting what the actual SQL query is that is causing this.
Comment #2
DamienMcKennaThis happens if, for some reason, the foreign key is not added to the file_metadata table.
Comment #3
DamienMcKennaIn my scenario the error was coming from a view that had the "View published content" permission.
Comment #4
DamienMcKennaFYi the problem may stem from #2064305: DB error on fresh install of module using sqlite where the primary key was changed. I noticed that after running through all of the database updates for alpha2, the table structure was left with a primary key but no foreign keys.
Comment #5
DamienMcKennaThis query should add the necessary foreign key:
ALTER TABLE file_metadata ADD CONSTRAINT file_managed FOREIGN KEY (fid) REFERENCES file_managed (fid);
Comment #6
DamienMcKennaFor my own notes, it was the gallery_content view, block_5 display.
Comment #7
DamienMcKennaJust to note, I was looking at the wrong table, the primary keys are correct on the {file_metadata} table.
Comment #8
DamienMcKennaFYI I'm resolving the issue on this one site by granting anon users and auth users the 'bypass file access' permission as we're not using file permissions at all, though obviously that's far from an ideal scenario.
Comment #9
DamienMcKennaFurther info - I added the foreign key to the table but the error still occurs.
Comment #10
Dave ReidI was going to say the file_metadata table likely wouldn't be the problem in the query - which is why getting the actual query would be helpful.
Comment #11
DamienMcKennaHere's the query I get from the Views admin:
Comment #12
DamienMcKennaPutting this back to the original bug as I opened another issue for the foreign key problem: #2069099: Foreign key missing on {file_metadata} table after updating to alpha2
Comment #13
Abhinesh Sharma CreditAttribution: Abhinesh Sharma commentedHi All,
It's File Entity version problem. If we are using File Entity 7.x-2.0-alpha2 with Media Module version 7.x-2.0-alpha2 . After install both module it's throw same error.
The Main Region is file Entity module some Time don't create file_metadata filed in Database. After you want to update the file entity version but you can't because file entity module don't provide uninstall option in back-end.
So If you have found any error like PDO table{file_managed} or Table {file_metadata} then Check Database table Structure.
Search 2 Tables in Database are exist or not
1) file_managed
2)file_metadata
and Please verify In file_managed table field "type" is exist or not. if not then create Field
type varchar(50) utf8_general_ci No undefined
And for file_metadata Please Run Below Query in Sql:-
--
-- Table structure for table `file_metadata`
--
CREATE TABLE IF NOT EXISTS `file_metadata` (
`fid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The file_managed.fid of the metadata.',
`name` varchar(255) NOT NULL COMMENT 'The name of the metadata (e.g. ’width’).',
`value` longblob COMMENT 'The value of the metadata (e.g. ’200px’).',
PRIMARY KEY (`fid`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Cache images dimensions.';
May this Post will help for use any version of File Entity and Media Module.
Thanks
Abhinesh