hope someone can help. I'm currently having a problem with view that are not reverting to code. What I did is creating a module for my view and exported them into code. I did this to get the structure out of the database and at the same be able to version control.

Using a views_default.inc, I have the following function in it:

function mymodule_views_default_views() {
    $files = file_scan_directory(drupal_get_path('module', 'mymodule') .'/views', '/\.view/');
    foreach ($files as $absolute => $file) {
       require $absolute;
       if (isset($view)) {
          $views[$file->name] = $view;
    return $views;

Each view has it's own .view file inside the views sub folder of my module. Files are named usng the view machine names. Once the module activated, I cleard the cache, view cache. Then reverted the views.

Out of the 46 views, I have 18 of them that don't show "In code" and still say "In database" with no option to revert. I've been looking around and trying to figure out why, but no luck.

These views are of different type...blocks, pages, reference, etc...

Does anyone know why some views would not revert? Thanks

  • Why not use the Features module to do the export? It provides neat option to export, and has drush support which makes the update and revert pretty easy. – AjitS Sep 28 '15 at 6:33
  • I reverted them using drush as well. There is a drush command to revert views. I could use features, but in the end I think it does the same thing. If I don't find any solution, I might try it. – TheGreatOne Sep 28 '15 at 23:21
  • 1
    This might be an issue with the view not exported properly. I faced this issue when a colleague of mine resolved a merge conflict in the view incorrectly, leaving the view exported from the features inconsistent. Rightly, it wasn't reverting. Had to export the view again to fix it. – AjitS Sep 29 '15 at 7:46
  • Yeah! That worked like a charm. I re-exported the views in the code file, flushed the cache and then reverted them. Now all my views shows in code! Never tough about this one since the view haven't change since the original export. Thanks Ajits! – TheGreatOne Sep 30 '15 at 1:06
  • It might have been the cache clearing that did the trick. I had a similar problem where drush vr <viewname> didn't work because the view was not overridden in the database. It doesn't seem to check against the original code then, so if you change the code nothing will happen. Clearing the views cache updated it to match the latest view code for me. – mickadoo May 23 '17 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.