diff --git a/flag.info.yml b/flag.info.yml
index 99e76a1..0efe501 100644
--- a/flag.info.yml
+++ b/flag.info.yml
@@ -4,3 +4,5 @@ core: 8.x
 type: module
 package: Flags
 configure: entity.flag.collection
+dependencies:
+  - dynamic_entity_reference:dynamic_entity_reference (2.x)
diff --git a/flag.views.inc b/flag.views.inc
index fe026bb..cc52bfe 100644
--- a/flag.views.inc
+++ b/flag.views.inc
@@ -4,6 +4,8 @@
  * Contains views API hooks for Flag module.
  */
 
+use Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem;
+
 /**
  * Implements hook_views_data().
  */
@@ -69,7 +71,7 @@ function flag_views_data_alter(array &$data) {
           'group' => t('Flag'),
           'label' => t('Flags'),
           'base' => 'flagging',
-          'base field' => 'entity_id',
+          'base field' => DynamicEntityReferenceItem::getTargetIdColumnName('flagging', 'flagged_entity', $entity_type_id),
           'relationship field' => $entity_type->getKey('id'),
           'id' => 'flag_relationship',
           'flaggable' => $entity_type_id,
diff --git a/src/Controller/FieldEntryFormController.php b/src/Controller/FieldEntryFormController.php
index 188c41d..e5f37bb 100644
--- a/src/Controller/FieldEntryFormController.php
+++ b/src/Controller/FieldEntryFormController.php
@@ -33,8 +33,10 @@ class FieldEntryFormController extends ControllerBase {
 
     $flagging = $this->entityTypeManager()->getStorage('flagging')->create([
       'flag_id' => $flag->id(),
-      'entity_type' => $flag->getFlaggableEntityTypeId(),
-      'entity_id' => $entity_id,
+      'flagged_entity' => [
+        'target_type' => $flag->getFlaggableEntityTypeId(),
+        'target_id' => $entity_id,
+      ],
       'uid' => $account->id(),
     ]);
 
diff --git a/src/Entity/Flag.php b/src/Entity/Flag.php
index 1235221..63d1995 100644
--- a/src/Entity/Flag.php
+++ b/src/Entity/Flag.php
@@ -2,14 +2,13 @@
 
 namespace Drupal\flag\Entity;
 
-use Drupal\Core\Access\AccessResult;
+use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
 use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Config\Entity\ConfigEntityInterface;
-use Drupal\flag\Event\FlagEvents;
 use Drupal\flag\FlagInterface;
 
 /**
@@ -511,9 +510,14 @@ class Flag extends ConfigEntityBundleBase implements FlagInterface {
     */
 
     // Reset the render cache for the entity.
-    \Drupal::entityTypeManager()
-      ->getViewBuilder($this->getFlaggableEntityTypeId())
-      ->resetCache();
+    try {
+      \Drupal::entityTypeManager()
+        ->getViewBuilder($this->getFlaggableEntityTypeId())
+        ->resetCache();
+    }
+    catch (InvalidPluginDefinitionException $e) {
+      // Nothing to do.
+    }
 
     // Clear entity extra field caches.
     // @todo Inject the entity field manager into the object?
diff --git a/src/Entity/Flagging.php b/src/Entity/Flagging.php
index 4234e84..65daf04 100644
--- a/src/Entity/Flagging.php
+++ b/src/Entity/Flagging.php
@@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Entity\ContentEntityBase;
 use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem;
 use Drupal\flag\Event\UnflaggingEvent;
 use Drupal\flag\FlaggingInterface;
 use Drupal\flag\Event\FlagEvents;
@@ -75,14 +76,14 @@ class Flagging extends ContentEntityBase implements FlaggingInterface {
    * {@inheritdoc}
    */
   public function getFlaggableType() {
-    return $this->get('entity_type')->value;
+    return $this->get('flagged_entity')->target_type;
   }
 
   /**
    * {@inheritdoc}
    */
   public function getFlaggableId() {
-    return $this->get('entity_id')->value;
+    return $this->get('flagged_entity')->target_id;
   }
 
   /**
@@ -117,19 +118,11 @@ class Flagging extends ContentEntityBase implements FlaggingInterface {
 
     // This field is on flaggings even though it duplicates the entity type
     // field on the flag so that flagging queries can use it.
-    $fields['entity_type'] = BaseFieldDefinition::create('string')
-      ->setLabel(t('Entity Type'))
-      ->setDescription(t('The Entity Type.'));
-
-    $fields['entity_id'] = BaseFieldDefinition::create('string')
-      ->setLabel(t('Entity ID'))
-      ->setRequired(TRUE)
-      ->setDescription(t('The Entity ID.'));
-
-    $fields['flagged_entity'] = BaseFieldDefinition::create('entity_reference')
-      ->setLabel(t('Entity'))
-      ->setDescription(t('The flagged entity.'))
-      ->setComputed(TRUE);
+    $fields['flagged_entity'] = BaseFieldDefinition::create('dynamic_entity_reference')
+      ->setLabel(t('Flagged entity'))
+      ->setDescription(t('The entity that has been flagged.'))
+      ->setCardinality(1)
+      ->setRequired(TRUE);
 
     // Also duplicates data on flag entity for querying purposes.
     $fields['global'] = BaseFieldDefinition::create('boolean')
@@ -155,10 +148,10 @@ class Flagging extends ContentEntityBase implements FlaggingInterface {
    * {@inheritdoc}
    */
   public function onChange($name) {
-    if ($name == 'entity_id' && $this->get('flagged_entity')->isEmpty()) {
+    if ($name == 'flagged_entity' && $this->get('flagged_entity')->isEmpty()) {
       $this->flagged_entity->target_id = $this->entity_id->value;
     }
-    if (in_array($name, ['flagged_entity', 'entity_id']) && $this->flagged_entity->target_id != $this->entity_id->value) {
+    if (in_array($name, ['flagged_entity', 'entity_id']) && $this->flagged_entity->entity->id() != $this->flagged_entity->target_id) {
       throw new \LogicException("A flagging can't be moved to another entity.");
     }
     parent::onChange($name);
diff --git a/src/Entity/Storage/FlaggingStorage.php b/src/Entity/Storage/FlaggingStorage.php
index 6acc43b..6624d85 100644
--- a/src/Entity/Storage/FlaggingStorage.php
+++ b/src/Entity/Storage/FlaggingStorage.php
@@ -5,6 +5,7 @@ namespace Drupal\flag\Entity\Storage;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem;
 
 /**
  * Default SQL flagging storage.
@@ -77,9 +78,9 @@ class FlaggingStorage extends SqlContentEntityStorage implements FlaggingStorage
     // Directly query the table to avoid he overhead of loading the content
     // entities.
     $query = $this->database->select('flagging', 'f')
-      ->fields('f', ['entity_id', 'flag_id', 'global'])
-      ->condition('entity_type', $entity_type_id)
-      ->condition('entity_id', array_keys($ids_to_load));
+      ->fields('f', ['flagged_entity__target_id', 'flag_id', 'global'])
+      ->condition('flagged_entity__target_type', $entity_type_id)
+      ->condition(DynamicEntityReferenceItem::getTargetIdColumnName('flagging', 'flagged_entity', $entity_type_id), array_keys($ids_to_load));
 
     // The flagging must either match the user or be global, avoid an empty IN
     // condition if there are no global flags.
@@ -102,12 +103,12 @@ class FlaggingStorage extends SqlContentEntityStorage implements FlaggingStorage
     // be returned.
     foreach ($result as $row) {
       if ($row->global) {
-        $this->globalFlagIdsByEntity[$entity_type_id][$row->entity_id][$row->flag_id] = $row->flag_id;
+        $this->globalFlagIdsByEntity[$entity_type_id][$row->flagged_entity__target_id][$row->flag_id] = $row->flag_id;
       }
       else {
-        $this->flagIdsByEntity[$account->id()][$entity_type_id][$row->entity_id][$row->flag_id] = $row->flag_id;
+        $this->flagIdsByEntity[$account->id()][$entity_type_id][$row->flagged_entity__target_id][$row->flag_id] = $row->flag_id;
       }
-      $flag_ids_by_entity[$row->entity_id][$row->flag_id] = $row->flag_id;
+      $flag_ids_by_entity[$row->flagged_entity__target_id][$row->flag_id] = $row->flag_id;
     }
 
     return $flag_ids_by_entity;
diff --git a/src/FlagCountManager.php b/src/FlagCountManager.php
index f9284b2..268e161 100644
--- a/src/FlagCountManager.php
+++ b/src/FlagCountManager.php
@@ -92,7 +92,7 @@ class FlagCountManager implements FlagCountManagerInterface, EventSubscriberInte
       $result = $this->connection->select('flagging', 'f')
         ->fields('f', ['flag_id'])
         ->condition('flag_id', $flag_id)
-        ->condition('entity_type', $entity_type)
+        ->condition('flagged_entity__target_type', $entity_type)
         ->countQuery()
         ->execute()
         ->fetchField();
diff --git a/src/FlagService.php b/src/FlagService.php
index 2488bfa..6175d9b 100644
--- a/src/FlagService.php
+++ b/src/FlagService.php
@@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\Query\QueryFactory;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem;
 use Drupal\user\UserInterface;
 
 /**
@@ -140,8 +141,11 @@ class FlagService implements FlagServiceInterface {
     }
 
     if (!empty($entity)) {
-      $query->condition('entity_type', $entity->getEntityTypeId())
-        ->condition('entity_id', $entity->id());
+      $query->condition('flagged_entity__target_type', $entity->getEntityTypeId())
+        // @todo Use the proper field when entity field queries support the _int
+        // column.
+        // ->condition(DynamicEntityReferenceItem::getTargetIdColumnName('flagged_entity', $entity->getEntityTypeId()), $entity->id());
+        ->condition('flagged_entity__target_id', $entity->id());
     }
 
     $ids = $query->execute();
@@ -159,8 +163,11 @@ class FlagService implements FlagServiceInterface {
       $query->condition('uid', $account->id());
     }
 
-    $query->condition('entity_type', $entity->getEntityTypeId())
-      ->condition('entity_id', $entity->id());
+    $query->condition('flagged_entity__target_type', $entity->getEntityTypeId())
+      // @todo Use the proper field when entity field queries support the _int
+      // column.
+      // ->condition(DynamicEntityReferenceItem::getTargetIdColumnName('flagged_entity', $entity->getEntityTypeId()), $entity->id());
+      ->condition('flagged_entity__target_id', $entity->id());
 
     $ids = $query->execute();
 
@@ -187,8 +194,11 @@ class FlagService implements FlagServiceInterface {
    */
   public function getFlaggingUsers(EntityInterface $entity, FlagInterface $flag = NULL) {
     $query = $this->entityQueryManager->get('flagging')
-      ->condition('entity_type', $entity->getEntityTypeId())
-      ->condition('entity_id', $entity->id());
+      ->condition('flagged_entity__target_type', $entity->getEntityTypeId())
+      // @todo Use the proper field when entity field queries support the _int
+      // column.
+      // ->condition(DynamicEntityReferenceItem::getTargetIdColumnName('flagged_entity', $entity->getEntityTypeId()), $entity->id());
+      ->condition('flagged_entity__target_id', $entity->id());
 
     if (!empty($flag)) {
       $query->condition('flag_id', $flag->id());
@@ -236,8 +246,10 @@ class FlagService implements FlagServiceInterface {
     $flagging = $this->entityTypeManager->getStorage('flagging')->create([
       'uid' => $account->id(),
       'flag_id' => $flag->id(),
-      'entity_id' => $entity->id(),
-      'entity_type' => $entity->getEntityTypeId(),
+      'flagged_entity' => [
+        'target_id' => $entity->id(),
+        'target_type' => $entity->getEntityTypeId(),
+      ],
       'global' => $flag->isGlobal(),
     ]);
 
@@ -294,8 +306,11 @@ class FlagService implements FlagServiceInterface {
   public function unflagAllByEntity(EntityInterface $entity) {
     $query = $this->entityQueryManager->get('flagging');
 
-    $query->condition('entity_type', $entity->getEntityTypeId())
-      ->condition('entity_id', $entity->id());
+    $query->condition('flagged_entity__target_type', $entity->getEntityTypeId())
+      // @todo Use the proper field when entity field queries support the _int
+      // column.
+      // ->condition(DynamicEntityReferenceItem::getTargetIdColumnName('flagged_entity', $entity->getEntityTypeId()), $entity->id());
+      ->condition('flagged_entity__target_id', $entity->id());
 
     $ids = $query->execute();
 
diff --git a/src/FlaggingViewsData.php b/src/FlaggingViewsData.php
index b39d37d..0c0fa07 100644
--- a/src/FlaggingViewsData.php
+++ b/src/FlaggingViewsData.php
@@ -24,7 +24,8 @@ class FlaggingViewsData extends EntityViewsData {
       'left_field' => 'flag_id',
       'field' => 'flag_id',
       'extra' => [[
-        'left_field' => 'entity_id',
+        // @todo Can we switch `target_id` and `target_id_int` as needed here?
+        'left_field' => 'flagged_entity__target_id',
         'field' => 'entity_id',
       ]],
     ];
diff --git a/src/Plugin/Derivative/EntityFlagTypeDeriver.php b/src/Plugin/Derivative/EntityFlagTypeDeriver.php
index 3aa348d..0e5fd90 100644
--- a/src/Plugin/Derivative/EntityFlagTypeDeriver.php
+++ b/src/Plugin/Derivative/EntityFlagTypeDeriver.php
@@ -16,8 +16,8 @@ class EntityFlagTypeDeriver extends DeriverBase {
   public function getDerivativeDefinitions($base_plugin_def) {
     $derivatives = array();
     foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_id => $entity_type) {
-      // Skip config entity types.
-      if (!$entity_type instanceof ContentEntityTypeInterface) {
+      // Skip entity types without labels.
+      if (!$entity_type->getLabel()) {
         continue;
       }
       $derivatives[$entity_id] = [
diff --git a/src/Tests/AdminUITest.php b/src/Tests/AdminUITest.php
index 4fadc3e..90e75c1 100644
--- a/src/Tests/AdminUITest.php
+++ b/src/Tests/AdminUITest.php
@@ -182,8 +182,8 @@ class AdminUITest extends FlagTestBase {
 
     $ids_before = $this->entityQueryManager->get('flagging')
       ->condition('flag_id', $this->flag->id())
-      ->condition('entity_type', 'node')
-      ->condition('entity_id', $this->node->id())
+      ->condition('flagged_entity__target_type', 'node')
+      ->condition('flagged_entity__target_id', $this->node->id())
       ->execute();
 
     $this->assertEqual(count($ids_before), 1, "The flag has one flagging.");
@@ -197,8 +197,8 @@ class AdminUITest extends FlagTestBase {
 
     $ids_after = $this->entityQueryManager->get('flagging')
       ->condition('flag_id', $this->flag->id())
-      ->condition('entity_type', 'node')
-      ->condition('entity_id', $this->node->id())
+      ->condition('flagged_entity__target_type', 'node')
+      ->condition('flagged_entity__target_id', $this->node->id())
       ->execute();
 
     $this->assertEqual(count($ids_after), 0, "The flag has no flaggings after being reset.");
diff --git a/tests/src/Kernel/FlagKernelTestBase.php b/tests/src/Kernel/FlagKernelTestBase.php
index bdc36e9..e80894d 100644
--- a/tests/src/Kernel/FlagKernelTestBase.php
+++ b/tests/src/Kernel/FlagKernelTestBase.php
@@ -23,7 +23,13 @@ abstract class FlagKernelTestBase extends KernelTestBase {
    *
    * @var array
    */
-  public static $modules = ['flag', 'node', 'user', 'system'];
+  public static $modules = [
+    'dynamic_entity_reference',
+    'flag',
+    'node',
+    'user',
+    'system',
+  ];
 
   /**
    * {@inheritdoc}
diff --git a/tests/src/Kernel/FlagServiceTest.php b/tests/src/Kernel/FlagServiceTest.php
index 6f57833..3ec1d33 100644
--- a/tests/src/Kernel/FlagServiceTest.php
+++ b/tests/src/Kernel/FlagServiceTest.php
@@ -194,4 +194,36 @@ class FlagServiceTest extends FlagKernelTestBase {
     }
   }
 
+  /**
+   * Tests flagging of config entities.
+   */
+  public function testFlagConfigEntity() {
+    // Create one user, then a user to flag with, just to ensure a higher uid
+    // than 1.
+    $this->createUser();
+    $account = $this->createUser();
+    $flag = Flag::create([
+      'id' => strtolower($this->randomMachineName()),
+      'label' => $this->randomString(),
+      'entity_type' => 'node_type',
+      'flag_type' => 'entity:node_type',
+      'link_type' => 'reload',
+      'flagTypeConfig' => [],
+      'linkTypeConfig' => [],
+    ]);
+    $flag->save();
+
+    $node_type = NodeType::create([
+      'type' => strtolower($this->randomMachineName()),
+      'name' => $this->randomString(),
+    ]);
+    $node_type->save();
+
+    $this->flagService->flag($flag, $node_type, $account);
+    $flagging_users = $this->flagService->getFlaggingUsers($node_type, $flag);
+    $this->assertEquals(1, count($flagging_users));
+    $this->assertTrue(in_array($account->id(), array_keys($flagging_users)));
+  }
+
+
 }
